Using an accumulator, "iterating"...

Brett Kelly bkelly@sourcereview.net
Fri, 20 Jun 2003 18:23:42 -0700


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

Hello all,

I'm trying to write a function that takes a list and a element (same type) =
and
returns the index of the first instance of the element in the list.  like:
getindex "brett" 'e' would return 2, etc.

i'm trying to accomplish this using an accumulator, here's what i've got:

pyindex :: Eq a =3D> a -> [a] -> Maybe Int
pyindex c l =3D pyindex' 0 chr (x:xs)
    where pyindex' count chr (x:xs) =3D do
        if x =3D=3D chr=20
          then return count
          else pyindex' (count + 1) chr xs

now, i know i've got a syntax problem, because i'm pretty sure my logic is
correct (or at least MOSTLY correct).

can anybody see what's wrong with my stuff?

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

Vim - this ain't your daddy's text editor
http://www.vim.org

--1UWUbFP1cBYEclgG
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iD8DBQE+87Oea7gYa9SI8SoRAq32AJ0cShOd6W6PnaFjTQyit6GvQx1hCwCgjNNN
A8IvsovD7aELRY4nhthT9fY=
=9TXQ
-----END PGP SIGNATURE-----

--1UWUbFP1cBYEclgG--