[Haskell-beginners] Do I understand this well

Lyndon Maydwell maydwell at gmail.com
Mon Jun 27 17:51:45 CEST 2011


Top-level bindings are done in ghci with let:

let (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)

On Mon, Jun 27, 2011 at 11:49 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
>
>
>
> ________________________________
>> Date: Mon, 27 Jun 2011 16:14:28 +0100
>> Subject: Re: [Haskell-beginners] Do I understand this well
>> From: colinpauladams at gmail.com
>> To: rwobben at hotmail.com
>>
>> No.
>>
>> You are onfusing defining a function with using it.
>>
>>
>> addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
>>
>> defines the function addVectors
>>
>> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
>>
>> calls the function, and binds x and y to the components of the result
>> (pattern matching).
>>
>> Alternatively:
>>
>> fst . addVectors (3.0, 4.5, -3.4, -5.6)
>>
>> will return the x-compnent of the result (by composing functions)
>>
>
>
> Oke,
>
>
>
> I understand that I think
>
> But when I ghci I enter :
>
>
> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
>
>
>
>
>
> after I made a file with the file defenition.
>
> I get this error :
>
>
>
> :1:7 parse error on input =
>
>
>
> So something is not right here.
>
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list