[Haskell-beginners] Lambda calc version of Haskell lambda function
Francesco Ariis
fa-ml at ariis.it
Fri Jan 1 09:58:16 UTC 2021
Il 31 dicembre 2020 alle 22:33 Lawrence Bottorff ha scritto:
> Here is a function declaration
>
> makeAddress :: Int -> String -> String -> (Int, String, String)
> makeAddress number street town = (number,street,town)
>
> and here is a lambda function version
>
> makeAddressLambda = (\number -> (\street -> (\town -> (number, street,
> town))))
You can lose most of the parentheses:
makeAddressLambda = \number -> \street -> \town -> (number, street, town)
> How would this lambda version look in lambda calculus? Like this?
>
> \number.\street.\town.(number street town)
Yes.
> then
>
> (\number.\street.\town.(number street town) (123 "Sunny St." "Fergus")
Wait! You have lost a ‘)’ on the lambdas (remember λ goes as far right as
possible). Also
(123, "Sunny St.", "Fergus")
makes it look like it is a single argument, which leads to a wrong result:
(λnumber. λstreet. λtown. number street town) (123, "Sunny St.", "Fergus")
λstreet. λtown. (123, "Sunny St.", "Fergus") street town
-- woops!
Instead, keeping in mind Haskell follows a beta-nu-mu strategy, we have
a series of 3 βs:
(λnumber. λstreet. λtown. (number, street, town)) 123 "Sunny St." "Fergus"
(λstreet. λtown. (123, street, town) "Sunny St." "Fergus"
(λtown. (123, "Sunny St.", town) "Fergus"
(123, "Sunny St.", "Fergus")
More information about the Beginners
mailing list