News for hackers. Stuff that matters.
Re:Haskell, Monads and Purity by dllthomas on Saturday October 04, 2014 @10:41AM (#8409588)
You can get rid of divide by zero without anything sophisticated. The key is that you cannot expose normal division. There are two reasonable solutions:

    Perform test in the operation:
    (/) :: i -> i -> Maybe i

    Require test before the operation:
    nonzero :: i -> Maybe (NonZero i)
    (/) :: i -> NonZero i -> i

Both of these come at a cost, of course, of making some arithmetic expressions look less natural - which dependent types could probably help with.

There are no comments on this comment yet.