On Sat, 24 Sep 2005, Marcin Tustin wrote:

> For some reason the following code is producing an error message from ghci 
> that the the patterns are non-exhaustive. Does anyone have any idea why that 
> could be, given that the patterns are, at least in my meaning, provably 
> exhaustive?
>
> choosenonuniqueset n (a:r)
>     | (length r) >  (n-1) = [ (sort (a:x)) | x <- (choosenonuniqueset (n-1) 
> r)]
>                             `union`
>                             [ (sort (a:x)) | x <- (choosenonuniqueset n r)]
>     | (length r) == (n-1) = [a:r]
>     | (length r) <  (n-1) = []

You need to compare only once. Better write:

choosenonuniqueset n (a:r) =
  case compare (length r) (n-1) of
     GT -> ...
     EQ -> [a:r]
     LT -> []

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to