Re:GADTs Meet Their Match [pdf]
by tikhonj on Friday October 09, 2015 @08:27PM
(#10363960)
Since Haskell is non-strict, how it handles diverging expressions is part of the semantics. If the expression never needs to be evaluated, it doesn't matter if it diverges or not.
I can't think of how to translate that to the examples of the paper, but there are functions where this distinction is useful. For example, it makes sense that getting the head of a list does not care whether the tail diverges or not:
head [] = Nothing
head (x:_) = Just x
> head (10:undefined)
Just 10
However, if we add a redundant-seeming case, this behavior changes:
head [] = Nothing
head [x] = Just x
head (x:_) = Just x
> head (1:undefined)
*Exception: Prelude.undefined
This example is a bit contrived, but I think it illustrates how the distinction can matter. I can't think of a self-contained example of where this is obviously useful, but it does come up in practical Haskell all the time, sometimes without people realizing it. (I remember somebody mentioning that making Haskell strict caused a whole bunch of code and common idioms to stop working correctly.)
I can't think of how to translate that to the examples of the paper, but there are functions where this distinction is useful. For example, it makes sense that getting the head of a list does not care whether the tail diverges or not:
However, if we add a redundant-seeming case, this behavior changes: This example is a bit contrived, but I think it illustrates how the distinction can matter. I can't think of a self-contained example of where this is obviously useful, but it does come up in practical Haskell all the time, sometimes without people realizing it. (I remember somebody mentioning that making Haskell strict caused a whole bunch of code and common idioms to stop working correctly.)