Need some help please.

Hal Daume t-hald@microsoft.com
Wed, 27 Aug 2003 14:03:23 -0700


There's a small problem with this solution, namely that it requires you
to have an Eq instance for the elements in the list.  You can fix this
by using 'null' from the Prelude.

 --
 Hal Daume III                                   | hdaume@isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume


> -----Original Message-----
> From: haskell-admin@haskell.org=20
> [mailto:haskell-admin@haskell.org] On Behalf Of b.i.mills@massey.ac.nz
> Sent: Wednesday, August 27, 2003 1:57 PM
> To: haskell@haskell.org
> Subject: Re: Need some help please.
>=20
>=20
> What is Nick Name doing? Trolling?
>=20
> I don't approve of people getting homework done on this emailing
> list, you learn more from doing, but baiting newbies is worse.
> You want to give them the idea that Haskell is complex and abtruse?
>=20
> > I need to define a function called safetail; it's like tail=20
> > except that this one maps the empty list to the empty list.=20
> > It has to be defined using the following:
>=20
> Ok, so logicaly, we are saying that we want (safeTail x) to be
> (tail x) if x is not [], but for x=3D=3D[] (normally an error) we=20
> want (safeTail []) =3D=3D []. Just write this down in Haskell ...
>=20
> safeCond x =3D if x=3D=3D[] then []=20
>                       else tail x
>=20
> Guards are just another way of producing conditional expressions
>=20
> safeGuard x | x=3D=3D[] =3D []=20
>             | True  =3D tail x
>=20
> And pattern matching likewise, for this simple example
>=20
> safePat [] =3D []
> safePat x =3D tail x
>=20
> If you want to test the result ...
>=20
> tester 0 safe =3D [(safe [])]
> tester n safe =3D (safe [1 .. n]) : (tester (n-1) safe)
>=20
> call it as (tester 10 safePat) for example, to get a list
> of some of the outputs from the safePat routine.
>=20
> Regards,
>=20
> Bruce.
>=20
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>=20