2007/11/8, Fernando Rodriguez <[EMAIL PROTECTED]>:
>
> Hi,
>
> This simple function definition that should rotate a list (put the first
> item in the last place) fails with a rather cryptic error with ghc:
>
> f :: [a] ->[a] ->[a]
> f (w : ws) = ws : w
>
> Couldn't match expected type `[a] -> [a]'
>      against inferred type `[[a]]'
> In the expression: ws : w
> In the definition of `f': f (w : ws) = ws : w
>
> What's Haskell trying to tell me? I'm a newby so please forgive my ignorance.

Hi,
  as haskell newbie I will try to explain. Launch ghci and write:

Prelude> :t (:)
(:) :: a -> [a] -> [a]

Now compare with types you got. What you want is probably something like this:

f :: [a] ->[a] ->[a]
f (w : ws) = ws ++ [w]

Prelude> :t (++)
(++) :: [a] -> [a] -> [a]

but I believe this is highly unefficient. You may also want to
experiment with tail, head and reverse to achieve what you want. But
others will probably tell you better ways to do it.

Cheers,
  Radek.


-- 
Codeside: http://codeside.org/
Przedszkole Miejskie nr 86 w Lodzi: http://www.pm86.pl/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to