[Haskell-beginners] Do I understand this well

Markus Läll markus.l2ll at gmail.com
Mon Jun 27 17:18:43 CEST 2011


addVectors is a function definition, so it doesn't actually do
anything until you apply it.

In addThree you would use it like this

> addThree vec1 vec2 vec3 = let
>       interm = addVectors vec1 vec2
>    in addVectors interm vec3

or

> addThree vec1 vec2 vec3 = addVectors interm vec3
>       where interm = addVectors vec1 vec2

or

> addThree vec1 vec2 vec3 = addVectors (addVectors vec1 vec2) vec3

or

> addThree vec1 vec2 vec3 = vec1 `addVectors` vec2 `addVectors` vec3

with the last one looking really nice.

In the first two I bind the result to an intermediate variable; in the
third the intermediate result is used inline; and the last one is
basically the same as third, but the function is used as an infix.

On Mon, Jun 27, 2011 at 5:51 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
>
>
> Hello,
>
>
>
> Im stil reading chapter4
>
>
>
> Now we have this : addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
>
>
>
> do I understand it that the outcome of x1+x2 will be saved in the last expression x1 + x2
>
> But on which variable can the outcome be found.
>
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Markus Läll



More information about the Beginners mailing list