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

Define currencies in terms of union type #2

Closed
3noch opened this issue Feb 23, 2018 · 3 comments
Closed

Define currencies in terms of union type #2

3noch opened this issue Feb 23, 2018 · 3 comments

Comments

@3noch
Copy link

3noch commented Feb 23, 2018

Since you already have Alpha, you could write a single function (maybe fromAlpha) which defines all currencies as a case over all Alphas. Then currencies becomes fromAlpha <$> [minBound..maxBound] and each currency function is either unnecessary or trivial (e.g. usd = fromAlpha USD).

@KtorZ
Copy link
Collaborator

KtorZ commented Feb 23, 2018

This. I like.

Thanks for the suggestion. I wanted to rework a bit the implementation anyway (noticed that compilation & runtime can be rather slow because of the default Read instance, writing it "by hand" speeds up things a lot. It seems that GHC doesn't like much big ADTs like this).

@KtorZ
Copy link
Collaborator

KtorZ commented Mar 13, 2018

Closed with eca59c3 👍

@KtorZ KtorZ closed this as completed Mar 13, 2018
@3noch
Copy link
Author

3noch commented Mar 13, 2018

Cool!

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

No branches or pull requests

2 participants