
GADTs Meet Their Match [pdf] - luu
http://research.microsoft.com/en-us/um/people/simonpj/papers/pattern-matching/gadtpm-acm.pdf
======
gizmo686
It seems like much of the difficulty this paper is dealing with is the fact it
is possible for expressions to diverge. Is their any case where this happening
would not be an error? If not, then wouldn't it make more sense to leave the
behaviour undefined, and have the compiler throw warnings when it detects this
possibility?

~~~
tikhonj
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.)

------
jstimpfle
It's interesting how haskell news most often score high but have very few
comments here.

~~~
riffraff
I consider those "aspirational" upvotes.

HNers like to think of this place as a community of smart people, so we upvote
stuff we think smart people should enjoy, even if effectively haven't payed
attention to the content.

~~~
throwupaway1138
waiting for insightful comments and summaries to be posted

