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
Feature Proposal: Monetary Units #96
Comments
This is an interesting request. Other people have mentioned wanting to have arbitrary counting units as well, e.g. "cars / year". Our current approach has a lot of merits, but ease of supporting this is not one of them. The problem is that we need to be able to use type families to take the type-level product of our type-level dimension type. Ideally instead of representing type-level dimensions by 7-tuples of integers, we could represent them by finite maps from @adamgundry's |
There's also @goldfirere's units package, which supports arbitrary user-defined units (with |
It would be really nice if we had the ability to declare new open kinds and inhabitants of them. The current way with I was thinking this same thing while listening to a presentation at Boston Haskell last week about
|
I'm unaware of any Trac ticket for this feature, but I very much think we should have it. And it would be easy to implement, I believe. The closest thing to a Trac ticket is https://ghc.haskell.org/trac/ghc/ticket/9840#comment:6 but that was me hijacking another ticket. I'm afraid I don't have the bandwidth to champion this now, though. But do please post a ticket and I'll support it! |
Will do. I agree with your suspicion that it's easy to implement, although I've certainly been wrong about that sort of thing in the past. Do you have any thoughts on what concrete syntax I should propose for declaring types that are in an open kind other than |
How about, for example, What's more difficult is the syntax for declaring inhabitants of an open kind. |
On the second bit, I checked and Would simply relaxing this restriction be enough to solve the syntax for declaring inhabitants of an open kind, yielding |
Yes, what you propose would work syntactically. But it's bogus semantically. The problem is that in For the term-level ideas: Right now, every (normal, non-promoted) datatype is closed. We declare all of its constructors all at once. But I've seen a desire to relax that restriction and allow for open datatypes. What we're discussing here is the same idea, one level up. I just want to future-proof the concrete syntax so that it will work if we ever work out the details one level down. |
Ahh, I get it now. I just had a lightbulb go on about wanting the same thing one level down (a need sort of met by Data.Unique in some circumstances, but not really because of the IO requirement, although I have seen some hacks for getting around that for top-level declarations). I came here to say so and you already had. OK, got it. I will propose this on GHC trac with these syntax suggestions and post the link here. |
See https://ghc.haskell.org/trac/ghc/ticket/11080 in which I hope I explained this adequately. |
I am closing this as out of scope for now. We may revisit that if and when a solution of open data kinds or full dependent types makes another model for dimension possible and even allows abstracting the whole library over a kind of dimensions. |
It would be great to be able to express units other than SI units, such as dollars. This would allow the type checker to manipulate amounts like "USD/day" in a type-checked way.
The text was updated successfully, but these errors were encountered: