
Oke, Now figure out how I can find the 3 in the list [1,2,3,4] I was thinking about using tail [1,2,3,4] and after that use last [1,2,3] So something like last [ tail [1,2,3,4] Or : let outcome = tail [1,2,3,4]let outcome2 = last [outcome] Roelof Date: Mon, 27 Jun 2011 15:20:18 +0300 From: mats.rauhala@gmail.com To: beginners@haskell.org Subject: Re: [Haskell-beginners] first number is a list On 12:08 Mon 27 Jun , Roelof Wobben wrote:
Sorry, Now Im missing you. First you talked about head[x:-] = x and now head [1,2,3,4] is good. Roelof Date: Mon, 27 Jun 2011 15:03:00 +0300
I wasn't entirely clear. The function declaration for head is: head (x:_) = x head _ = error "No elements" or something similar. You can see from this that it uses pattern matching to find the first element (x:_). _ means that the value is disgarded. [1,2,3,4] is just syntactic sugar for 1 : 2 : 3 : 4 : [], so pattern matching (x:_) finds 1 from the previous list. You use the function head like I mentioned in the last email; `head [1,2,3,4]`. Try firing up ghci and inputting that in it. -- Mats Rauhala MasseR _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners