[Haskell-beginners] Haskell as a useful practical 'tool' for intelligent non-programmers

Michael Orlitzky michael at orlitzky.com
Sun Apr 29 16:56:10 CEST 2012


On 04/29/2012 10:28 AM, Lorenzo Bolla wrote:
>>
>> What's the difference? You're not passing around the actual function, in
>> any language.
> 
> $ python
> Python 2.7.3 (default, Apr 14 2012, 23:17:33) 
> [GCC 4.7.0 20120407 (prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> def f():
> ...     print 'foo'
> ... 
>>>> def g(f):
> ...     print 'bar'
> ...     f()
> ... 
>>>> g(f)
> bar
> foo
> 
> Also: http://en.wikipedia.org/wiki/First-class_function#Language_support
> 

You're not passing around the function, you're passing around the name
of the function or a pointer. Python happens to know that when you write
f(), you want to evaluate the function named f, much like when you say
f.call() in Ruby.

Ruby doesn't even have functions, only methods, so you have to entertain
the idea that the same thing can have two different names to even have
this discussion. Passing functions to other functions is so fundamental
to Ruby that it's baked into the language:

  irb(main):001:0> [1, 2, 3].map { |x| 2*x }
  => [2, 4, 6]

They're not called functions, but the distinction is imaginary. For an
imperative language, the culture pretty strongly encourages you to use
map, filter, fold etc. which are all passed functions (Procs) using the
block syntax.



More information about the Beginners mailing list