On Fri, Sep 16, 2011 at 2:34 PM, Albert Y. C. Lai <tre...@vex.net> wrote: > On 11-09-15 10:24 PM, Michael Litchard wrote: >> >> Someone commented on StackOverflow that pattern matching the first >> element of a list was preferable to head. This makes sense >> intuitively. Could someone articulate the reason why this is true? > > if null s then e0 else ...(head s)...(tail s)... > > is a clumsy way to say > > case s of > [] -> e0 > h:t -> ...h...t... > > The clumsy way is more familiar because it is popularized by lisp. It is the > way in lisp because lisp is old.
I have 'head :: [a] -> Maybe a' along with tail, maximum/minimum and various other prelude functions that, IMHO, shouldn't have been partial. I agree case is often better, but sometimes Maybe is convenient, e.g. when composing with other Maybes. And I can pass it easily to 'maybe', but then I suppose someone is going to say I should define 'b -> (a -> [a] -> b) -> [a] -> b' and use that directly :) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe