KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
F# has a units of measure capability, described at http://msdn.microsoft.com/en-us/library/dd233243.aspx as follows: [<Measure>] type unit-name [ = measure ] This allows units to be defined such as: type [<Measure>] USD type [<Measure>] EUR And code to be written as: let dollars = 25.0<USD> let euros = 25.0<EUR> // Results in an error as the units differ if dollars > euros then printfn "Greater!" It also handles conversions (I'm guessing that means Measure has some functions defined that let Measures be multiplied, divided and exponentiated): // Mass, grams. [<Measure>] type g // Mass, kilograms. [<Measure>] type kg let gramsPerKilogram: float<g kg^-1> = 1000.0<g/kg> let convertGramsToKilograms (x: float<g>) = x / gramsPerKilogram My instincts tell me it should be possible to implement a similar capability in Haskell, but I've not been able to find any examples of how to do it. Edit: oh my word it's a huge can of worms! There's a research paper at http://research.microsoft.com/en-us/um/people/akenn/units/CEFP09TypesForUnitsOfMeasure.pdf . I'm guessing it's more than a few lines of code to implement the whole thing. Summer project anyone? :)
Tags (comma-separated)
Save Edits
Cancel