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

Mike Meyer mwm at mired.org
Sun Apr 29 08:35:41 CEST 2012

On Sun, 29 Apr 2012 01:20:22 -0400
Michael Orlitzky <michael at orlitzky.com> wrote:

> On 04/29/2012 12:15 AM, Mike Meyer wrote:
> > On Sat, 28 Apr 2012 22:22:34 -0400
> > 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 =)
> > 
> > I respectfully disagree. For instance, I could have said that it uses
> > indentation to delimit blocks like ABC does. That's much less true.
> > 
> > But I believe the statement about functions not being first class
> > objects is true. Of course, I don't use ruby on a regular basis
> > because that turns out to be the case every time I go look at it. If
> > the language has changed so this can be done in a manner that's as
> > straightforward as Python, I'd be interested in hearing about it.
> They're wrapped in Proc objects, but those objects can be treated like
> any other in the language. Everything else is just syntactic sugar on
> top of Procs.

That makes *Procs* first class object, not functions.

> This is not conceptually any different to me than in Haskell or C; you
> have a name for the thing, distinct from the thing itself, and you have
> to ask for function application via (f x), f(x), f.call(x), or whatever.

And if having the same set of concepts were all that mattered, we'd
still PERFORMing blocks of code.  The syntax of a language makes some
things easier to do, and some things harder - that's why there's more
than one of them. Writing HOFs is harder in ruby than in a language
with first-class functions, because you can't pass a function to a
function.  You have to decide which of the workarounds you want to use
(blocks or lambdas or Methods or Procs or ...). If you want to use a
function from the standard library - you have to wrap it in order to
pass it to your HOF. Since "all of the above" isn't a valid choice, if
you're trying to use a library of HOFs (assuming such exist in Ruby -
and if they don't, that's yet another reason Ruby isn't a good way to
get to Haskell), you may wind up wrapping some things multiple times,
or wrap the results of your HOFs, or ... well, you get the idea.

None of this makes Ruby any better or worse for anything other than
writing code in a functional style. There are perfectly usable
languages that can't do HOFs at all. That you can do it at all makes
Ruby a better choice than them for writing functional code. But it
requires a lot of code that's nothing more than boilerplate, which
makes it worse than languages that don't require such.

Of course, if you don't think boilerplate makes things harder, and all
that matters is having the same concepts, then I expect you won't
argue if I claim that there's no reason to pick Ruby over Java for
writing OO code. After all, they have the same concepts, just with
different syntactic sugar and more or less boilerplate.

Mike Meyer <mwm at mired.org>		http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

More information about the Beginners mailing list