by pbhjpbhj · 11y ago · 0 comments
>"had an easy time explaining how (2 * 3) really is two functions, each with one argument and one result, and he drew it out on paper nicely" //
So, like you pass the multiply function an argument which is a list (2, 3). Or is it more like you pass the multiply function the first operand (2 in this case) and it returns a function multiply-by-2 which you pass the second operand? The latter seems like it would get sub-optimal pretty quickly. Mind you surely here the compiler produces the same sort of assembly [repeated addition here] making it just a way to abstract around an alternate mental model.
I've just looked at https://wiki.haskell.org/Currying, could someone walk through how something like arcsin(0) works - that's probably a bad example - something that takes a single variable input but has multiple solutions (returns n.π in this case, but say sqrt or an anagram function or ...)?
I'm sure you can tell I'm not a computer scientist, not even a programmer ...
This is exactly it. You can literally write:
multiply_by_2 = (*) 2
map (* 2) [1, 2, 3]
will take that function and apply it to each element in the list [1,2,3].Thanks for the responses - I'm now almost as knowledgeable as a 10 yo prior to being instructed in the subject at hand.
define
double_list_elements = map (*2)
and
> double_list_elements [1, 2, 3, 4]
gives you [2, 4, 6, 8]