haskell-scheme
haskell-scheme copied to clipboard
Add float support.
trafficstars
Adds a new type for which numeric operations mixing ints/floats are defined. Sure could use some refactoring but fuck me if I know why ghc would not let me.
Quite ad hoc. Ought to be a nicer way to do this. Something something typeclasses?
You could add something like
numValToFloat :: NumVal -> Float
numValToFloat (Float f) = f
numValToFloat (Integer i) = fromInteger i
to make all the other functions a lot shorter, e.g.
(+) (Integer a) (Integer b) = Integer $ a+b
(+) a b = Float $ (numValToFloat a)+(numValToFloat b)
also note that you can define infix operators without writing them prefix, like so:
Integer a + Integer b = Integer $ a + b
a + b = Float $ numValToFloat a + numValToFloat b
finally, adding tests would probably be a good idea ^^