
27 Jun
2011
27 Jun
'11
12:20 p.m.
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