[Haskell-beginners] Again on list manipulations

Alex Rozenshteyn rpglover64 at gmail.com
Fri Sep 10 11:03:03 EDT 2010


well,
> selFn = map (\x -> (! x)) sel -- This is not necessarily the most elegant
way to word it
would return a list of functions, which, when applied to a list, return an
element from it based on the index
> results = map ($ ml) selFn
would solve your problem

alternatively (and more cleanly),
> results = map (ml !) sel

On Fri, Sep 10, 2010 at 10:55 AM, Lorenzo Isella
<lorenzo.isella at gmail.com>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
>
> Lorenzo
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
          Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100910/415f0997/attachment.html


More information about the Beginners mailing list