Difference between revisions of "Talk:Generalised algebraic datatype"

From HaskellWiki
Jump to navigation Jump to search
 
 
Line 1: Line 1:
  +
== Pattern Match Warnings ==
  +
 
Sort of a practical question here...
 
Sort of a practical question here...
   
Line 13: Line 15:
 
</pre>
 
</pre>
   
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 <code>List x NonEmpty</code>, then the only patterns to match on are <code>Cons</code> (because those are the only ones that return List x NonEmpty)? Or is there some theoretical barrier to this?
+
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 <code>List x NonEmpty</code>, then the only patterns to match on are <code>Cons</code> (because those are the only ones that return List x NonEmpty)? Or is there some theoretical barrier to this? -- [[User:EricKow|EricKow]] 17:37, 26 July 2006 (UTC)

Latest revision as of 17:37, 26 July 2006

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)