[Haskell-cafe] Re: defining last using foldr

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Aug 16 05:11:24 EDT 2007


"Chaddaï Fouché" <chaddai.fouche at gmail.com> writes:
> > so you need an f so that c `f` x is c (for any c and x) and
> > yet (b `f` c) is c for any c and b -- this is impossible (or
> > I'm asleep).
> 
> Well, it isn't "impossible" but quite hard (and not even standard H98
> if I'm not mistaken) 

If it is possible, I'm very sad that we've allowed things to
get into the language that make that kind of reasoning
faulty.

> Still you could "approximate" it, and in fact I believe the [Char] ->
> Char requirement is hinting at such a (arguably and IMO ugly)
> solution. For example you could assume there would be no "NUL"
> character in a string ([Char] is a synonym for String, or vice-versa),
> and then get a simple myLast for String in this restrictive case (and
> looking exactly like Alexteslin sample).

I certainly wouldn't count such a thing as a valid
solution. It's always amazed me that C uses as standard a
mechanism of ending strings that is so obviously an
error-prone hack.

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-Cafe mailing list