[Haskell-cafe] Re: Currying confusion

John Goerzen jgoerzen at complete.org
Fri Nov 12 14:56:58 EST 2004


On 2004-11-12, Henning Thielemann <iakd0 at clusterf.urz.uni-halle.de> wrote:
>
> On Fri, 12 Nov 2004, John Goerzen wrote:
>
>> I like the partial application feature (and used it in test1).  So, I
>> thought I could use that to my advantage in test3 and test4:
>> 
>> test3 :: Int -> Int -> String
>> test3 x f = (show x) ++ f
>
> You mean
>
> test3 :: Int -> (Int -> String) -> String
>
> ?

Yes.

> Then the implementation could be written as
>
> test3 x f = (show x ++) . f

Tried that, but:

test.hs:13:
    Couldn't match `String' against `Int -> [Char]'
        Expected type: String
        Inferred type: Int -> [Char]
    In the expression: (((show x) ++)) . f
    In the definition of `test3': test3 x f = (((show x) ++)) . f

>
>
> But I believe currying means conversion between functions of two arguments
> and functions of pairs. 
>
>
> pairMap :: (a -> b) -> (a,a) -> (b,b)
> pairMap f (x,y) = (f x, f y)
>
> test5 :: Int -> Int -> String
> test5 = curry (uncurry (++) . pairMap show)
>
> This is something including partial application and currying. Is this what
> you are looking for? 


-- 
John Goerzen
Author, Foundations of Python Network Programming
http://www.amazon.com/exec/obidos/tg/detail/-/1590593715



More information about the Haskell-Cafe mailing list