[Haskell-beginners] Haskell as a useful practical 'tool' for intelligent non-programmers
Lyndon Maydwell
maydwell at gmail.com
Sun Apr 29 04:37:38 CEST 2012
Your first example is not behaving how you think it is...
ruby-1.9.2-p0 :012 > def foo
ruby-1.9.2-p0 :013?> puts "foo"
ruby-1.9.2-p0 :014?> end
=> nil
ruby-1.9.2-p0 :015 > def call_arg(f)
ruby-1.9.2-p0 :016?> puts "calling"
ruby-1.9.2-p0 :017?> f
ruby-1.9.2-p0 :018?> end
=> nil
ruby-1.9.2-p0 :019 > call_arg(foo)
foo
calling
=> nil
Note that "foo" is printed before "calling".
On Sun, Apr 29, 2012 at 10:22 AM, Michael Orlitzky <michael at orlitzky.com> wrote:
> On 04/28/2012 08:47 PM, Mike Meyer wrote:
>>
>> Ruby makes a bad fit if Haskell is a goal (and that's a good
>> goal). Ruby functions aren't first-class objects, and can't simply be
>> passed to other functions as arguments.
>
> That's like, the least true thing you can say about Ruby =)
>
> A simple test program:
>
> $ cat fcf.rb
> def foo
> puts "foo"
> end
>
> def call_arg(f)
> f
> end
>
> call_arg(foo)
>
>
> Running it:
>
> $ ruby fcf.rb
> foo
>
>
> Moreover, every function and method implicitly accepts a function as an
> argument:
>
> $ cat yield.rb
> def call_block
> yield
> end
>
> call_block { puts "foo" }
>
> This allows you some nice do-block syntactic sugar instead of lambdas
> which can get ugly.
>
> $ ruby yield.rb
> foo
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list