functional programming - Elm: understanding foldp and mouse-clicks -


i'm learning elm. relatively new functional programming. i'm trying understand example http://elm-lang.org/learn/using-signals.elm on counting mouse-clicks. provide following code:

clickcount =     foldp (\click count -> count + 1) 0 mouse.clicks  

they explain foldp takes 3 arguments: counter-incrementer, defined anonymous function 2 inputs, starting state 0, , mouse.clicks signal.

i not understanding why need variable click in our anonymous function. why can't have \count -> count + 1? input getting bound 1 of our inputs foldp?

thanks!

you need because foldp expects function 2 inputs. in case, first input ignored lambda, foldp implementation still puts in there. mouse.clicks puts sort of do-nothing value called unit in there.

some signals have value associated them, mouse.position, example. if wanted measure how far mouse has moved, need use parameter.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -