What does uncurry ($) do?

后端 未结 4 480
面向向阳花
面向向阳花 2020-12-15 09:04

I\'m doing some excersises where I have to add a function\'s type and explain what it does. I\'m stuck with this:

phy = uncurry ($)

The typ

4条回答
  •  清歌不尽
    2020-12-15 09:36

    uncurry :: (a -> b -> c) -> (a, b) -> c
    
    ($) :: (a -> b) -> a -> b
    
    uncurry ($) :: (a -> b, a) -> b
    

    If you inspect types of uncurry and $ and its description:

    uncurry converts a curried function to a function on pairs.

    All it does is it takes a function (a -> b -> c) and returns a function that takes the parameters as a tuple.

    So phy does the same thing as $, but instead of f $ x or ($) f x you call it like phy (f, x).

提交回复
热议问题