If: x = [1,2,3] :: [Int] y = [0] :: [Int] z = 0 then: [y,x] == [[0],[1,2,3]] :: [[Int]] - a list of lists. It doesn't get simplified into [0,1,2,3]. (z,x) == (0,[1,2,3]) :: (Int, [Int]) - a tuple, whose first element is an Int, and whose second element is a list of Ints ([Int]) z:x == [0,1,2,3] :: [Int] The third one is what you're looking for. It's called "cons." Tom On 7/12/11, Roelof Wobben <rwobben@hotmail.com> wrote:
Hello,
I use Programming in Haskell from Graham Hutton.
But I can't find anything in the first 4 chapters from that book why I must use (0,x) en what that means.
Roelof
----------------------------------------
Date: Tue, 12 Jul 2011 15:21:46 -0400 Subject: Re: [Haskell-beginners] safetail problem From: amindfv@gmail.com To: rwobben@hotmail.com CC: beginners@haskell.org
_ isn't a value: it's a wildcard character for pattern matching.
Also, if x = [1,2,3], [0,x] is the wrong way to make a list. The right way is (0:x) (":" is "cons")
What resource are you learning from?
On 7/12/11, Roelof Wobben <rwobben@hotmail.com> wrote:
Hello,
As a exercise I need to rewrite the tail function into a safetail function by using conditions.
So I made this : http://codepad.org/bKcCUdqy
But as you can see there is a error message.
Can anyone explain me how to solve this ?
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners