diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-12 14:23:01 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-12 15:31:38 +0100 |
| commit | 37e52bff39a1fe4d442cb253773252030c1cab8a (patch) | |
| tree | 9942561e55e3a51947b87c6f35ac5181f3dff71c /src/complex.hs | |
| parent | dbbc2f6798ba77d2ea7d9cce91d3bd1879e467a2 (diff) | |
| download | computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.tar.gz computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.tar.bz2 computorv2-37e52bff39a1fe4d442cb253773252030c1cab8a.zip | |
Basic expression parsing
Diffstat (limited to 'src/complex.hs')
| -rw-r--r-- | src/complex.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/complex.hs b/src/complex.hs new file mode 100644 index 0000000..220fe1f --- /dev/null +++ b/src/complex.hs @@ -0,0 +1,17 @@ +module Complex where + +type Imaginary = Float + +data Complex = Complex Float Imaginary + +-- instance Num Complex where +-- (Complex r1 i1) + (Complex r2 i2) = Complex (r1 + r2) (i1 + i2) +-- (Complex r1 i1) * (Complex r2 i2) = undefined +-- negate (Complex r1 i1) = undefined +-- abs (Complex r1 i1) = undefined +-- signum (Complex r1 i1) = undefined + -- fromInteger r = Complex r 0 + +instance Show Complex where + show (Complex r i) = show r ++ showI ++ "i" + where showI = if i < 0 then " - " ++ show (-i) else " + " ++ show i |
