[Haskell-cafe] Typing problems with basic arithmetic - help!
lemming at henning-thielemann.de
Mon Sep 26 06:41:26 EDT 2005
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)]
> [ (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 -> 
More information about the Haskell-Cafe