Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add float support. #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add float support. #7

wants to merge 3 commits into from

Conversation

whagsv
Copy link

@whagsv whagsv commented Aug 10, 2020

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?

@steffahn
Copy link
Contributor

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 ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants