DEV Community

Discussion on: 7 Easy functional programming techniques in Go

Collapse
 
the2bears profile image
William Swaney

I don't think that's really "currying", just a higher order function that takes one argument ("x") returning a different function that closes around the value of "x".

Collapse
 
deepu105 profile image
Deepu K Sasidharan

As far as I know, that is exactly what currying is en.m.wikipedia.org/wiki/Currying?w.... Care to explain why you think its not

Collapse
 
the2bears profile image
William Swaney • Edited

The code certainly performs the task of currying in a limited subset of my impression of the meaning. I agree, that in this case you have a function (add) that takes two arguments and you supply the first, returning a function that only requires the second argument.

When I think of currying, though, I think more of how Haskell supports it, where it's automatic and baked right into the language. You might have:

my-fun :: Integer ->  Integer -> Integer -> Integer

This is a function that takes 3 Integers, returning an Integer. In this case, (my-fun 10) is a function taking 2 integers, returning one. This can be done as you showed, with a series of higher order functions, but it has to be explicitly done.

A more interesting problem is how to deal with functions that have multi-arity? It can be done, again, with lots of explicit creation of what turns out to be a lot of boiler plate.

Anyway, sorry if my original post was curt. Your "add" example shows some of what I consider currying, but I don't think Go, Scala, Clojure, etc. can do it all (at least easily) so I think it's better describing this as using higher order functions.

Thread Thread
 
deepu105 profile image
Deepu K Sasidharan

Currying is a concept and is definitely not based on how Haskel does it AFAIK. You can do currying even in Java using lambda and stuff. The idea is to make the concept possible and not in the syntax IMO