
Hello, could someone please give me an example of the "partial application" of the following curried function: add' :: Int -> Int -> Int add' a b = a + b Normally, add' 1 should work, but it doesn't. Many thanks. phiroc

phiroc:
Hello,
could someone please give me an example of the "partial application" of the following curried function:
add' :: Int -> Int -> Int add' a b = a + b
Normally, add' 1 should work, but it doesn't.
Prelude> let add' :: Int -> Int -> Int ; add' a b = a + b Prelude> let add1 = add' 1 Prelude> add1 7 8 -- Don

Quoth phiroc@free.fr, nevermore,
could someone please give me an example of the "partial application" of the following curried function:
add' :: Int -> Int -> Int add' a b = a + b
Normally, add' 1 should work, but it doesn't.
I think this is what you mean. If not, then please advice. This is typed into a vanilla ghci prompt, no extra modules loaded or flags switched on. There is no smoke and mirrors at work ;-) (The ':: Int' constrains the type of b, and therefore all the other numbers, but doesn't affect the function application.)
Prelude> let add' a b = a + b :: Int Prelude> let f = add' 1 Prelude> f 2 3
Is this what you wanted? Perhaps you tried this but mistyped something?
Regards,
D.
--
Dougal Stanton

On Thu, Jan 18, 2007 at 10:26:25AM +0100, phiroc@free.fr wrote:
To: haskell-cafe@haskell.org From: phiroc@free.fr Date: Thu, 18 Jan 2007 10:26:25 +0100 Subject: [Haskell-cafe] Partial application
Hello,
could someone please give me an example of the "partial application" of the following curried function:
add' :: Int -> Int -> Int add' a b = a + b
Normally, add' 1 should work, but it doesn't.
it does work for me: | *Main> add' 1 | | Top level: | No instance for (Show (Int -> Int)) | arising from use of `print' at Top level | Probable fix: add an instance declaration for (Show (Int -> Int)) | In a 'do' expression: print it perhaps you didn't understand the error message? it is not about the outcome itself, it just states that the output cannot be displayed. (Int -> Int) is a type that doesn't "show". hth, m
participants (4)
-
dons@cse.unsw.edu.au
-
Dougal Stanton
-
Matthias Fischmann
-
phiroc@free.fr