[Haskell-beginners] Again on list manipulations

Henry Olders henry.olders at mcgill.ca
Fri Sep 10 13:48:17 EDT 2010

On 2010-09-10, at 10:55 , Lorenzo Isella wrote:

> Dear All,
> I know this must be a one-liner, but it am banging my head against the wall.
> I am trying my hands at list manipulation in Haskell and a lot of useful 
> function are making my life easier but I cannot achieve something really 
> simple.
> Let us say you have the lists ml and sel
> ml=[23,44,55,8,98]
> and
> sel=[1,2] .
> Now, I would like simply to get a new list whose entries are the 
> elements of ml in position sel. In my case things might be a little more 
> complicated because all the elements are Integer and not Int (I noticed 
> that sometimes this means I have to resort to generic functions).
> Cheers

What about nested list comprehensions:

[x|(x,y)<-zip ml [x `elem` sel | x <- [1..maximum sel]], y]


More information about the Beginners mailing list