Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

F# has units of measure[1], which lets you use units on numeric types. It also does unit conversion, so if you have a function (x * x), the type sig would be "x:int<m> -> int<m ^ 2>". Pretty neat.

Without the neat inherent aspects, any language with lightweight support for phantom types can achieve some level of this functionality.

For instance, you could define a sum type with only one case taking the type to wrap. Thus you can easily have TransactionId, AccountId, etc. as distinct types, without spending more than a line to declare them.

1: http://msdn.microsoft.com/en-us/library/dd233243.aspx



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: