[Haskell] View patterns in GHC: Request for feedback

Dan Licata drl at cs.cmu.edu
Wed Jul 25 06:01:28 EDT 2007

Hi everyone,

Thanks for all the helpful feedback!  It's great to see what people

Let me just respond to one point at the moment:

I think that the signature
>    type Typ
>    unit :: Typ -> Maybe ()
>    arrow :: Type -> Maybe (Typ,Typ)

is *wrong* if what you really mean is

>    type Typ
>    data TypView = Unit | Arrow Typ Typ
>    view :: Typ -> TypView

That is, if what you mean is that every Typ is either Unit or an Arrow
*and nothing else* then the latter signature should be preferred, as it
makes this fact explicit in the type system.  In former signature, it's
implicit: you have to say externally that a group of destructors, taken
together, define a total view.  When programming with the former
signature, you always have an extra case to consider, in which all of
the destructors fail.

The whole point of sum types is that they tell you exactly what cases
you have to consider.  There's a big difference between the type A and
the type A+1, and you should use the type system to track this
difference (or else you end up wiht things like null pointer exceptions
in Java).

To my mind, the syntactic considerations of which way you prefer to
write your view patterns should not outweigh this important semantic


More information about the Haskell mailing list