Hi,
> length' 1:2:3:[]
is equivalent to:
> (length' 1):2:3:[]
hence the error.
Try:
> length' (1:2:3:[])
Sylvain
Hello all,
I am a rank beginner to functional languages. Working through Lipovaca's book, up to Chapter 3.
Ok, setup this function in editor and compiled:
length' :: (Num b) => [a] -> blength' [] = 0length' (_:xs) = 1 + length' xs
skippy@skippy:~$ ghciGHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for helpPrelude> :l baby[1 of 1] Compiling Main ( baby.hs, interpreted )Ok, modules loaded: Main.*Main> length' [1,2,3]3*Main> 1:2:3:[][1,2,3]*Main> length' 1:2:3:[]
<interactive>:5:9:Could not deduce (Num [a0]) arising from the literal ‘1’from the context (Num a)bound by the inferred type of it :: Num a => [a]at <interactive>:5:1-16The type variable ‘a0’ is ambiguousIn the first argument of ‘length'’, namely ‘1’In the first argument of ‘(:)’, namely ‘length' 1’In the expression: length' 1 : 2 : 3 : []*Main>
Obviously, there is something I don't understand about the apparent non-equivalence of the lists [1,2,3] and 1:2:3:[]I am guessing that the solution is contained in that error message but I can't quite decipher it.
Thanks for any help.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners