[Haskell-beginners] Further constraining types

Thomas haskell at phirho.com
Thu Aug 4 12:49:11 CEST 2011


> Once you've validated your user input though, nothing prevents you to
> have it return a Positive Int that you will guarantee can hold only
> positive integers, for example by using a smart constructor, and
> hiding the contructor in a separate module. You don't need dependant
> types for this.

Yes, but once you want to operate on that data you'll note the difference:

subtract :: Positive Int -> Positive Int -> ???

IIUC with dependent types you'll have a compile time guarantee, without 
you'll have to test for errors at runtime.

Regards,
Thomas



More information about the Beginners mailing list