[Haskell-cafe] More death to partial functions: Should -fwarn-incomplete-uni-patterns be enabled with -Wall?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Nov 8 09:49:18 UTC 2015


On Sun, Nov 08, 2015 at 10:42:35AM +0100, Joachim Breitner wrote:
> Am Sonntag, den 08.11.2015, 09:30 +0000 schrieb Tom Ellis:
> > Simon's code is inadvisable, in my opinion.  It is
> > 
> >     f xs | null xs = blah
> >          | otherwise = x+1
> >          where
> >            (x:_) = xs
> > 
> > where it really should be
> > 
> >     f xs = case xs of []    -> blah
> >                       (x:_) -> x + 1
> > 
> 
> yes, in this particular, small example
> 
> But often you have complex decisions in the guards that are not
> obviously related to the pattern match, and the where-bound and
> partially-pattern-matched value are used in multiple branches of the
> guard.

I can't address less particular, larger, examples until I'm shown them, but
I am going to make the very bold claim that there's *always* a version
without partial pattern matches that is at least as clear as the original. 
I strongly encourage you to challenge me on this claim!

Tom


More information about the Haskell-Cafe mailing list