Is a section the result of currying?

前端 未结 3 722
遇见更好的自我
遇见更好的自我 2021-01-26 00:24

In Programming in Haskell by Hutton

In general, if # is an operator, then expressions of the form (#),

3条回答
  •  庸人自扰
    2021-01-26 01:12

    curry f x y = f (x,y). uncurry g (x,y) = g x y.

    (+ 3) 4 = (+) 4 3 = 4 + 3. (4 +) 3 = (+) 4 3 = 4 + 3.

    A section is a result of partial application of a curried function: (+ 3) = flip (+) 3, (4 +) = (+) 4.

    A curried function (like g or (+)) expects its arguments one at a time. An uncurried function (like f) expects its arguments in a tuple.

    To partially apply an uncurried function we have first to turn it into a curried function, with curry. To partially apply a curried function we don't need to do anything, just apply it to an argument.

    curry   :: ((a, b)  -> c ) -> ( a -> (b -> c))
    uncurry :: (a -> (b -> c)) -> ((a, b)   -> c )
    
     x :: a
     g :: a -> (b -> c)       
    --------------------
     g    x ::  b -> c  
    
     x       ::  a
     f       :: (a, b)   -> c
    ---------------------------
     curry f ::  a -> (b -> c)
     curry f     x ::  b -> c
    

提交回复
热议问题