[Haskell-cafe] Stupid error, probably

b1g3ar5 nick.straw at gmail.com
Mon Oct 12 19:03:24 EDT 2009

I can't get the following to work in Leksah - but it works OK in GHC.
Can anyone spot the error?

I wondered if it was becasue the libraries loaded are different - but
I'm just a Haskell beginner ...

I have:

myGroupBy :: Int→  [a]→  [[a]]
myGroupBy = takeWhile not . null . (unfoldr (Just . (splitAt 3)))

and I am getting the error:

    Couldn't match expected type `Int' against inferred type `[a]'
    In the second argument of `(.)', namely `(splitAt 3)'
    In the first argument of `unfoldr', namely `(Just . (splitAt 3))'
    In the second argument of `(.)', namely
        `(unfoldr (Just . (splitAt 3)))'

But I think that

splitAt :: Int->[a]->([a],[a])


splitAt 3 :: [a]->([a], [a])


Just.(splitAt 3) :: [a]->Maybe ([a], [a])

which seems OK as the first argument of unfoldr:

unfoldr ::  (b-> Maybe(a,b))->b->[a]

with the a and b of unfoldr being [a] and [a].

The mention of Int in the error makes me wonder if I've got the wrong
splitAt - with the arguments reversed maybe.

Any ideas?



More information about the Haskell-Cafe mailing list