Haskell currying explanation needed
I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that
f is the curried form of g
Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?
From the haskell documentation
Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.
f :: a -> b -> c
is the curried form of
g :: (a, b) -> c
So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.
haskell currying
add a comment |
I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that
f is the curried form of g
Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?
From the haskell documentation
Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.
f :: a -> b -> c
is the curried form of
g :: (a, b) -> c
So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.
haskell currying
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06
add a comment |
I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that
f is the curried form of g
Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?
From the haskell documentation
Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.
f :: a -> b -> c
is the curried form of
g :: (a, b) -> c
So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.
haskell currying
I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that
f is the curried form of g
Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?
From the haskell documentation
Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.
f :: a -> b -> c
is the curried form of
g :: (a, b) -> c
So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.
haskell currying
haskell currying
asked Aug 22 '18 at 9:03
Wouter VandenputteWouter Vandenputte
3942415
3942415
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06
add a comment |
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06
add a comment |
2 Answers
2
active
oldest
votes
Yet
f
takes two arguments andg
only one.
No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.
If you write a signature like:
f :: a -> b -> c
then this is a less verbose form of:
f :: a -> (b -> c)
How does that work? f
is a function that takes one parameter, and then returns another function that again takes a parameter.
So take for example a function add :: Int -> Int -> Int
.
If we write add 5 2
, we thus calculate 5 + 2
. It looks like it takes two parameters, but in fact we have written (add 5) 2
. We thus call the add
function with 5
as parameter. This returns a function (let us call this function add5 :: Int -> Int
). So this add5
function adds 5
to a number. So if we then call add5 2
, then we obtain 7
, since add5
returns 5
added to the parameter.
We can however construct a function (like g
) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2)
is actually g (5, 2)
: you call the function with one parameter, a 2-tuple (5, 2)
.
So the currying aims to transform such g
function that takes one parameter (a 2-tuple) into a function f
that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.
add a comment |
The type a -> b -> c
is actually a -> (b -> c)
.
So f
doesn't take two arguments, of type a
and a b
and return c
, it takes one argument of type a
, and returns b -> c
, a function from b
to c
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51963290%2fhaskell-currying-explanation-needed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yet
f
takes two arguments andg
only one.
No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.
If you write a signature like:
f :: a -> b -> c
then this is a less verbose form of:
f :: a -> (b -> c)
How does that work? f
is a function that takes one parameter, and then returns another function that again takes a parameter.
So take for example a function add :: Int -> Int -> Int
.
If we write add 5 2
, we thus calculate 5 + 2
. It looks like it takes two parameters, but in fact we have written (add 5) 2
. We thus call the add
function with 5
as parameter. This returns a function (let us call this function add5 :: Int -> Int
). So this add5
function adds 5
to a number. So if we then call add5 2
, then we obtain 7
, since add5
returns 5
added to the parameter.
We can however construct a function (like g
) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2)
is actually g (5, 2)
: you call the function with one parameter, a 2-tuple (5, 2)
.
So the currying aims to transform such g
function that takes one parameter (a 2-tuple) into a function f
that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.
add a comment |
Yet
f
takes two arguments andg
only one.
No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.
If you write a signature like:
f :: a -> b -> c
then this is a less verbose form of:
f :: a -> (b -> c)
How does that work? f
is a function that takes one parameter, and then returns another function that again takes a parameter.
So take for example a function add :: Int -> Int -> Int
.
If we write add 5 2
, we thus calculate 5 + 2
. It looks like it takes two parameters, but in fact we have written (add 5) 2
. We thus call the add
function with 5
as parameter. This returns a function (let us call this function add5 :: Int -> Int
). So this add5
function adds 5
to a number. So if we then call add5 2
, then we obtain 7
, since add5
returns 5
added to the parameter.
We can however construct a function (like g
) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2)
is actually g (5, 2)
: you call the function with one parameter, a 2-tuple (5, 2)
.
So the currying aims to transform such g
function that takes one parameter (a 2-tuple) into a function f
that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.
add a comment |
Yet
f
takes two arguments andg
only one.
No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.
If you write a signature like:
f :: a -> b -> c
then this is a less verbose form of:
f :: a -> (b -> c)
How does that work? f
is a function that takes one parameter, and then returns another function that again takes a parameter.
So take for example a function add :: Int -> Int -> Int
.
If we write add 5 2
, we thus calculate 5 + 2
. It looks like it takes two parameters, but in fact we have written (add 5) 2
. We thus call the add
function with 5
as parameter. This returns a function (let us call this function add5 :: Int -> Int
). So this add5
function adds 5
to a number. So if we then call add5 2
, then we obtain 7
, since add5
returns 5
added to the parameter.
We can however construct a function (like g
) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2)
is actually g (5, 2)
: you call the function with one parameter, a 2-tuple (5, 2)
.
So the currying aims to transform such g
function that takes one parameter (a 2-tuple) into a function f
that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.
Yet
f
takes two arguments andg
only one.
No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.
If you write a signature like:
f :: a -> b -> c
then this is a less verbose form of:
f :: a -> (b -> c)
How does that work? f
is a function that takes one parameter, and then returns another function that again takes a parameter.
So take for example a function add :: Int -> Int -> Int
.
If we write add 5 2
, we thus calculate 5 + 2
. It looks like it takes two parameters, but in fact we have written (add 5) 2
. We thus call the add
function with 5
as parameter. This returns a function (let us call this function add5 :: Int -> Int
). So this add5
function adds 5
to a number. So if we then call add5 2
, then we obtain 7
, since add5
returns 5
added to the parameter.
We can however construct a function (like g
) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2)
is actually g (5, 2)
: you call the function with one parameter, a 2-tuple (5, 2)
.
So the currying aims to transform such g
function that takes one parameter (a 2-tuple) into a function f
that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.
answered Aug 22 '18 at 9:13
Willem Van OnsemWillem Van Onsem
151k16149238
151k16149238
add a comment |
add a comment |
The type a -> b -> c
is actually a -> (b -> c)
.
So f
doesn't take two arguments, of type a
and a b
and return c
, it takes one argument of type a
, and returns b -> c
, a function from b
to c
.
add a comment |
The type a -> b -> c
is actually a -> (b -> c)
.
So f
doesn't take two arguments, of type a
and a b
and return c
, it takes one argument of type a
, and returns b -> c
, a function from b
to c
.
add a comment |
The type a -> b -> c
is actually a -> (b -> c)
.
So f
doesn't take two arguments, of type a
and a b
and return c
, it takes one argument of type a
, and returns b -> c
, a function from b
to c
.
The type a -> b -> c
is actually a -> (b -> c)
.
So f
doesn't take two arguments, of type a
and a b
and return c
, it takes one argument of type a
, and returns b -> c
, a function from b
to c
.
answered Aug 22 '18 at 9:09
Daniel MrozDaniel Mroz
1914
1914
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51963290%2fhaskell-currying-explanation-needed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.
– molbdnilo
Aug 22 '18 at 9:22
Possible duplicate of What is 'Currying'?
– AJFarmar
Aug 22 '18 at 10:06