[Haskell-cafe] Re: Partial Application

Johan Grönqvist johan.gronqvist at gmail.com
Thu Jan 18 16:39:44 EST 2007

Philippe de Rochambeau skrev:
> Hello,
  > multiply :: Int -> Int -> Int
> multiply x y = x * y
> ....
> In the case of multiplications we can write expression like multiply 2".
> When I read this, I thought that you could partially apply "multiply" by 
> typing "multiply 2" at the ghci prompt. However, this generated an error:

You can

let mul2 = multiply 2 in mul2 5

this should give 10 at the ghci prompt

> <interactive>:1:0:
>     No instance for (Show (Int -> Int))
>       arising from use of `print' at <interactive>:1:0-9
>     Possible fix: add an instance declaration for (Show (Int -> Int))
>     In the expression: print it
>     In a 'do' expression: print it

This error says that the result is of a type that ghci cannot print. The 
type here is Int -> Int. The object "multiply 2" is a function, and 
there is no way of printing functions built into ghci.

(Ghci can display elements of types that are instances of the Show 
typeclass, and the error complains that there is no instance Show (Int 
-> Int), i.e. no prescription for displaying functions of type Int -> Int.)

> After reading http://www.haskell.org/hawiki/PartialApplication, I 
> figured out that you can only partially apply declared functions, in 
> source files, not at the prompt:

Again. They can be created at the prompt, but the funcion-value can not 
be displayed as text.

> multiplyBy2 = multiply 2
> Now "multiplyBy2 50" yields "100"

let multiply2 = multiply 2
multiply2 50

This should give 100 at the prompt

/ johan

More information about the Haskell-Cafe mailing list