[Haskell-beginners] Re: mayBe stuck

Brent Yorgey byorgey at seas.upenn.edu
Sat Aug 7 04:26:10 EDT 2010


On Fri, Aug 06, 2010 at 09:06:24PM -0700, prad wrote:
> On Fri, 6 Aug 2010 13:38:56 +0100
> Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> 
> 
> > you shift the burden of proving that it is safe from the compiler
> > onto yourself
> > ...
> > Here are some off the top of my head, for
> > beginners reading this who might not already know:
> > 
> >   fromJust
> >   head
> >   tail
> >   init
> >   last
> >   (!!)
> >
> i'm trying to follow this conversation. the problem is that some of
> these functions don't behave nicely for some inputs right? like tail []

All of these functions are "partial", which means that they are
undefined (crash with an error) for some inputs.  If possible you
should try to program only with "total" functions (functions which are
defined for every input) since then you know your program will not crash.

> 
> also, is it better to use pattern matching (x:xs) than head and tail?
> could that be part of the point here too?

Yes, that's exactly right.


-Brent


More information about the Beginners mailing list