Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Value access in lambda function (Emanuel Koczwara)
----------------------------------------------------------------------
Message: 1
Date: Sat, 29 Dec 2012 15:26:43 +0100
From: Emanuel Koczwara <[email protected]>
Subject: Re: [Haskell-beginners] Value access in lambda function
To: Divam <[email protected]>
Cc: [email protected]
Message-ID: <1356791203.2514.38.camel@emanuel-Dell-System-Vostro-3750>
Content-Type: text/plain; charset="UTF-8"
Hi,
> Brandon, I need to study this again, still dont understood how its
> related to partial function application.
>
Take a look at:
http://learnyouahaskell.com/higher-order-functions#lambdas
addThree :: (Num a) => a -> a -> a -> a
addThree x y z = x + y + z
can be defined as:
addThree :: (Num a) => a -> a -> a -> a
addThree = \x -> \y -> \z -> x + y + z
and with brackets it would be:
addThree = \x -> (\y -> (\z -> (x + y + z)))
Now, you just need to put brackets to see what's going on there (i've
simplified your code for clarity):
t v = Just v >>? \v1 -> Just (v + 1) >>? \v2 -> Just (v + v1 + v2)
This would be (it actually is!):
t v = Just v >>? \v1 -> (Just (v + 1) >>? \v2 -> (Just (v + v1 + v2) ) )
Now, if you will put braces in wrong place:
t v = Just v >>? (\v1 -> Just (v + 1)) >>? (\v2 -> Just (v + v1 + v2))
Then you will get: Not in scope: `v1'
> Also consider this: in Haskell, a function is a binding like any
> other. If you couldn't refer to bindings from outer scopes, you
> couldn't define new functions! Well, aside from anonymous
> ones/lambdas, which are useful but somewhat limiting if you can't name
> and reuse them.
>
>
> Brandon, This is quite strange thing, the functions can access the
> globally defined variables and therefore there output is dependent not
> just on inputs but on those variables too. This goes against the
> understanding of pure functions.
These 'global expressions' do not change during execution, output is
dependent only on input, and function could be defined in terms of
arguments and some 'constants' ('global expressions') and other
functions (also 'global expressions' (there is no difference).
Emanuel
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 48
*****************************************