[Haskell-cafe] Re: Matching constructors

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Fri Feb 10 14:26:49 EST 2006


Mark T.B. Carroll wrote:
> Creighton Hogg <wchogg at primula.hep.wisc.edu> writes:
>> data Patootie = Pa Int | Tootie Int
>> and I want to pull out the indices of all elements of a list 
>> that have type constructor Tootie, how would I do that?
> 
> x = [Pa 3, Tootie 5, Pa 7, Tootie 9, Pa 11]
> y = [ i |    Tootie i  <- x ]
> z = [ i | i@(Tootie _) <- x ]

I think this is what the OP wanted:

     [ i | (i,Tootie _) <- zip [0..] x ]

-- Ben



More information about the Haskell-Cafe mailing list