Using an accumulator, "iterating"...

Brett Kelly bkelly@sourcereview.net
Fri, 20 Jun 2003 19:02:09 -0700


--NU0Ex4SbNnrxsi6C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Awesome, thanks!

Sometime around Fri, Jun 20, 2003 at 09:47:54PM -0400, mike castleman said:
> On Fri, Jun 20, 2003 at 06:23:42PM -0700, Brett Kelly wrote:
> > now, i know i've got a syntax problem, because i'm pretty sure my logic=
 is
> > correct (or at least MOSTLY correct).
>=20
> Try:
>=20
> pyindex :: Eq a =3D> a -> [a] -> Maybe Int
> pyindex c l =3D pyindex' 0 l
>     where pyindex' _ [] =3D Nothing
>           pyindex' n (x:xs) =3D if (x =3D=3D c)
>                               then Just n
>                               else pyindex' (n+1) xs
>=20
>=20
> then, in ghci:
> Pyindex> pyindex 'e' "brett"
> Just 2
> Pyindex> pyindex 'm' "brett"
> Nothing
> Pyindex> pyindex 't' "brett"
> Just 3
>=20
> hope this helps.
> mike
>=20
> --=20
> mike castleman / m at mlcastle dot net / http://mlcastle.net / (646) 382-=
7220
> aolim: mlcastle / icq: 3520821 / yahoo: mlc000
> please avoid sending me microsoft word, excel, or powerpoint documents.
> see http://www.gnu.org/philosophy/no-word-attachments.html for more info.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

--=20
Brett Kelly
bkelly@sourcereview.net
This message has been digitally autographed using GnuPG.

Open Source software will continue to change the world...
http://www.opensource.org

--NU0Ex4SbNnrxsi6C
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+87yha7gYa9SI8SoRAsqlAJ4ikvHqHTuFB3pDo+fpuvNMmptrGwCfXwiD
FGLX3xSCe/EQPR8DESjq16o=
=oH5Z
-----END PGP SIGNATURE-----

--NU0Ex4SbNnrxsi6C--