HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Talk:Generalised algebraic datatype

Pattern Match Warnings

Sort of a practical question here...

data Empty
data NonEmpty

data List x y where
     Nil :: List a Empty
     Cons:: a -> List a b ->  List a NonEmpty

safeHead:: List x NonEmpty -> x
safeHead (Cons a b) = a

If I try to compile the above code with all warnings on, I get a pattern match non-exhaustive warning on safeHead because I'm not matching on Nil. This is pretty annoying. Is this the kind of thing that can easily be fixed? Can the compiler somehow magically recognise that if I've got a List x NonEmpty, then the only patterns to match on are Cons (because those are the only ones that return List x NonEmpty)? Or is there some theoretical barrier to this? -- EricKow 17:37, 26 July 2006 (UTC)

Retrieved from "http://haskell.org/haskellwiki/Talk:Generalised_algebraic_datatype"

This page has been accessed 606 times. This page was last modified 17:37, 26 July 2006. Recent content is available under a simple permissive license.