exists . a psuedo-standard non-empty list module

I don't particularly like using fromJust or head, and there's been plenty of discussion on those issues. For the cases where it makes good sense to do so, I'm about to write a module for non-empty lists that looks to strike a balance between usability and static checks. But before I re-invent the wheel, I was wondering if there's already a popular module along those lines. I would also appreciate references to your favorite discussion about uses of head and other unsafe functions or various Oleg posts showing how they're all unnecessary. I'll find these on my own, but I would also like to know which ones strike a chord with the community. Thanks for your time. -Nick

On Thu, 15 Feb 2007, Nicolas Frisby wrote:
I would also appreciate references to your favorite discussion about uses of head and other unsafe functions or various Oleg posts showing how they're all unnecessary. I'll find these on my own, but I would also like to know which ones strike a chord with the community.

Hi Nick,
On 2/16/07, Nicolas Frisby
I don't particularly like using fromJust or head, and there's been
IMHO I think that isJust/fromJust could simply be removed. Using 'maybe' is a much better practice, it is safe and much even more expressive. head on the other hand might be considered more necessary but right now I cannot think of a situation in which it's use shows any advantage over simple pattern matching. It's anyway worth to check Neil's Safe library http://www-users.cs.york.ac.uk/~ndm/projects/safe/Safe.html

Hi
IMHO I think that isJust/fromJust could simply be removed. Using 'maybe' is a much better practice, it is safe and much even more expressive.
Yes, its more expressive if you let someone write (error "Umm, what should I do here?") as one of the options. And now you've gone from something with a clear precondition, to something that merely floats a lazy _|_ value around the place. If you take that route be careful with strictness annotations!
head on the other hand might be considered more necessary but right now I cannot think of a situation in which it's use shows any advantage over simple pattern matching.
You can map head over a list, a function is a first class citizen. To make a pattern match into a first class item you need to turn it into a case or a lambda. Either way you can't import/export pattern matches from modules etc. I like both fromJust and head, they have clearly defined meanings, although obviously you have to be slightly careful about their use. Fortunately the problem of pattern match errors is being tackled by at least two projects: * Catch: http://www-users.cs.york.ac.uk/~ndm/projects/catch.php * ESC-Haskell: http://www.cl.cam.ac.uk/~nx200/research/escH-hw.ps Neither has a practical released tool yet, but hopefully that will have changed in a few months!
It's anyway worth to check Neil's Safe library http://www-users.cs.york.ac.uk/~ndm/projects/safe/Safe.html
Despite the fact that I like head/fromJust etc, a safe list library would be kind of handy. If someone wants to roll that into the Safe library, as Safe.List or something, I'd be happy to accept patches (saving someone else the hassle of setting up a new library etc, for roughly the same purpose) Thanks Neil

Despite the fact that I like head/fromJust etc, a safe list library would be kind of handy. If someone wants to roll that into the Safe library, as Safe.List or something, I'd be happy to accept patches (saving someone else the hassle of setting up a new library etc, for roughly the same purpose)
Thanks
Neil
That sounds like a great option. Candidate numero uno as of now. What I have in mind right now should be pretty light weight, but it will mostly be a regurgitation of code I've seen floating around. Some of the code from the previous wiki link, type-level decimal numbers I saw in an Oleg paper (I think), etc. Would you be open to such code in your library? Anyone have a better place for it? Nick

Hi Nick
That sounds like a great option. Candidate numero uno as of now. What I have in mind right now should be pretty light weight, but it will mostly be a regurgitation of code I've seen floating around. Some of the code from the previous wiki link, type-level decimal numbers I saw in an Oleg paper (I think), etc.
I am happy to accept a Safe list implementation much the same way as Oleg's implementation. The Safe library is a place to put code which allows the user to write code which ensures their are no pattern match errors, or to give better error messages when there are pattern match errors. Something like a type level implementation of decimals, if not directly concerned with this, might be better in a separate library for type level computation. Something like http://www.eecs.tufts.edu/~rdocki01/typenats.html
Would you be open to such code in your library? Anyone have a better place for it?
Yep, just send in a patch :) Thanks Neil
participants (4)
-
Alfonso Acosta
-
Henning Thielemann
-
Neil Mitchell
-
Nicolas Frisby