Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24501
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2014-05-30 19:17 -0700 |
| References | <da2909bd-58cc-4183-8b3c-167039985491@googlegroups.com> <02dfeef2-b8fa-4cc3-8c6f-d375a43278ca@googlegroups.com> <2c61b020-8e0c-4a3b-a021-f7058aed52dc@googlegroups.com> <72aa659a-997d-4d1a-97bb-87ffef38978c@googlegroups.com> <0eda5ddb-5a7a-4fa6-8d4c-219034645bcb@googlegroups.com> |
| Message-ID | <6adc900a-ed11-45f5-b7bf-413a2b5018a6@googlegroups.com> (permalink) |
| Subject | Re: ANN: Ramda, a new functional programming library |
| From | John C <rescattered@gmail.com> |
On Friday, May 30, 2014 4:39:21 PM UTC-4, Scott Sauyet wrote:
> John C wrote:
>
> > Scott Sauyet wrote:
>
> >> The funny thing is that I'd forgotten we'd taken these out of the
>
> >> library in response to a disagreement over how to handle the case
>
> >> where the user supplied an empty list. At some point we'll probably
>
> >> put them back, but they're not there now. When they do come back,
>
> >> maybe we'll use `selfFoldl`.
>
>
>
> (I'm sorry about the poor formatting earlier. The updated Google Groups
>
> was one of the reasons I've been gone for a while. I'm sorry to see
>
> that it's as bad as ever!)
>
>
>
> > Out of curiosity -- what was the disagreement? Returning undefined
>
> > seems like the natural choice since the result is, well, undefined
>
> > in this case. Is the concern with the way undefined is sometimes
>
> > quirky in javascript?
>
>
>
> Then you will agree with my coauthor, who argued for the same thing.
>
> We had a long discussion about this, captured here:
>
>
>
> <https://github.com/CrossEye/ramda/issues/20>
>
>
>
> The original implementation, following Haskell, raised an exception in
>
> this case. My coauthor didn't like this, thinking that we should return
>
> `undefined`. I, in turn, didn't like returning anything that might make
>
> the user have to type-check her results. Neither of us was really
>
> willing to budge, and as these were not very important to either of us,
>
> it was easier to simply remove the functions and see if something didn't
>
> settle out of it eventually. This was, I think, the only significant
>
> disagreement we've had over the time we've spent on this.
>
>
>
> Eventually, it came down to his preference list, which looked like this:
>
>
>
> 1. remove foldl1/foldr1 from the library
>
> 2. return undefined for empty list
>
> 3. throw exception
>
>
>
> and mine, which looked like this:
>
>
>
> 1. throw exception
>
> 2. remove foldl1/foldr1 from the library
>
> 3. return undefined for empty list
>
>
>
> At that point, it was pretty clear that the easiest thing was to remove
>
> these functions. They are easy enough to add back if someone wants. And
>
> maybe we will at some point.
>
>
>
> -- Scott
I guess I was thinking in terms of the Principle of Least Astonishment (POLA).
JavaScript already has some functional features, so I would think that
a library for functional programming in JavaScript should extend what is
already there rather than rewriting it. It should be possible to take
an existing program in JavaScript which has strong functional features
and somewhat easily rewrite it using the library. In particular -- code
which already uses JavaScript's reduce should be easily modified to run
using the new folding functions that you provide. Thus, I would expect
that selfFold would be more or less equivalent to:
function selfFold(f,xs)
{
return xs.slice(1).reduce(f,xs[0]);
}
with e.g. add(x,y) defined as {return x+y;} this yields
selfFold(add,[3,5,7]); // => 15, as expected
but we also have
selfFold(add,[]); // => undefined
which is also completely expected to a JavaScript programmer.
Thus *unless there is a compelling reason to do otherwise*, POLA would
suggest that an implementation of selfFold would return undefined on an
empty list.
On the other hand, I haven't thought about the issue much, and am open to
the claim that in e.g. the importance of having a consistent approach to error
handling across a library might outweigh POLA in this case.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-27 20:13 -0700
Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-27 21:00 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 04:37 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 04:36 -0700
Re: ANN: Ramda, a new functional programming library "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-05-28 08:49 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 15:59 -0700
Re: ANN: Ramda, a new functional programming library "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-05-28 16:15 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 17:05 -0700
Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 14:53 +0200
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:14 -0700
Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-05-29 19:40 +0100
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-29 17:55 -0700
Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 14:05 +0200
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:10 -0700
Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 06:25 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:23 -0700
Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 12:44 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 13:39 -0700
Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 19:17 -0700
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-31 09:52 -0700
Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-31 22:24 +0200
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 06:55 -0700
Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-31 21:00 +0200
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 06:54 -0700
Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-01 19:05 +0100
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 19:28 -0700
Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-03 22:01 +0100
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-03 19:15 -0700
Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-05 23:41 +0100
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-06 11:36 -0700
Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-07 23:13 +0100
Re: ANN: Ramda, a new functional programming library billyroberts111@gmail.com - 2016-03-06 10:22 -0800
Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-06 17:52 -0800
Re: ANN: Ramda, a new functional programming library "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-07 10:50 +0100
csiph-web