operator-sections

Partial Application with Infix Functions

给你一囗甜甜゛ 提交于 2019-12-10 01:34:57
问题 While I understand a little about currying in the mathematical sense, partially applying an infix function was a new concept which I discovered after diving into the book Learn You a Haskell for Great Good. Given this function: applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x) The author uses it in a interesting way: ghci> applyTwice (++ [0]) [1] [1,0,0] ghci> applyTwice ([0] ++) [1] [0,0,1] Here I can see clearly that the resulting function had different parameters passed, which

How to understand this `$` usage in Haskell [duplicate]

徘徊边缘 提交于 2019-12-08 01:08:21
问题 This question already has answers here : What does $ mean/do in Haskell? (2 answers) Closed 5 years ago . This happens in the situation you want to apply bunch of functions to the same variable, it may look like this: map (\f->f 4) [odd, even] but from LYAH using $ make it very neat map ($ 4) [odd, even] why does it work. first I type it in ghci like $ 4 odd , it failed, then I type ($ 4) odd , which works fine. then I check the type of ($ 4) using :t which shows ($ 4) :: Num a => (a -> b) ->

How to understand this `$` usage in Haskell [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-06 06:46:04
This question already has answers here : What does $ mean/do in Haskell? (2 answers) Closed 5 years ago . This happens in the situation you want to apply bunch of functions to the same variable, it may look like this: map (\f->f 4) [odd, even] but from LYAH using $ make it very neat map ($ 4) [odd, even] why does it work. first I type it in ghci like $ 4 odd , it failed, then I type ($ 4) odd , which works fine. then I check the type of ($ 4) using :t which shows ($ 4) :: Num a => (a -> b) -> b , odd is odd :: Integral a => a -> Bool . It seems make sense, but still not clear to me. Can anyone

Partial Application with Infix Functions

戏子无情 提交于 2019-12-05 00:31:50
While I understand a little about currying in the mathematical sense, partially applying an infix function was a new concept which I discovered after diving into the book Learn You a Haskell for Great Good . Given this function: applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x) The author uses it in a interesting way: ghci> applyTwice (++ [0]) [1] [1,0,0] ghci> applyTwice ([0] ++) [1] [0,0,1] Here I can see clearly that the resulting function had different parameters passed, which would not happen by normal means considering it is a curried function (would it?). So, is there any

Is a section the result of currying?

ε祈祈猫儿з 提交于 2019-12-04 05:47:11
问题 In Programming in Haskell by Hutton In general, if # is an operator, then expressions of the form (#) , (x #) , and (# y) for arguments x and y are called sections, whose meaning as functions can be formalised using lambda expressions as follows: (#) = \x -> (\y -> x # y) (x #) = \y -> x # y (# y) = \x -> x # y What are the difference and relation between "section" and "currying"? Is a section the result of applying the currying operation to a multi-argument function? Thanks. 回答1: Left