Live data from Hacker News

Make the Type System Do the Work

nathan.ca

11–20 of 141 posts

Re: Make the Type System Do the Work

#12
post #6

The Boost.Units[1] library takes this even further, allowing you to do things like divide a length by a time quantity and get a velocity, again with compile-time type checking. [1]: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_units.ht...

F# has similar also: http://en.wikibooks.org/wiki/F_Sharp_Programming/Units_of_Me...

Re: Make the Type System Do the Work

#16
This is a good trick but it needs to be used judiciously or you'll end up with lots of boilerplate.

I particularly like Go's type system, though, because it makes it very simple:

  type celsius float64
There's no overhead and it doesn't attempt to prevent you from doing any calculations as a float64; the type checking just prevents direct assignments from a celsius type to another type.

Re: Make the Type System Do the Work

#17
This is fairly the premise of OOP on display. And fairly basic at that. Im not sure whats to be learned here except that in the real world, your representations will always need to be extended and subclassing is usually a bad hammer.

Interfaces are better but extend poorly through subclassing as well.

Composition is infinite but difficult to define over time when things change (usually resorts to more subclassing or more injection strategies).

I wish this article were valuable to solving the actual problem but its just a primer on OOP vs using primitives which is not particularly instructive or useful to solving real world problems.

Re: Make the Type System Do the Work

#18

To take this to the current state of the art, look at Haskell, Agda, and Idris. Latter two being dependently typed. Steps for learning Haskell: https://gist.github.com/bitemyapp/8739525

What are your impressions of the three languages?

Personally, I'm learning Haskell first, because Haskell is the most popular of the three and there is plenty of good learning material. As far as Adga and Idris go, I think Idris looks more appealing.

Post reply on HN