[Haskell-beginners] best way to code this~~

briand at aracnet.com briand at aracnet.com
Tue Jun 2 03:35:57 UTC 2015


On Mon, 01 Jun 2015 16:10:47 +0000
Alex Hammel <ahammel87 at gmail.com> wrote:

Thank you so much for all the info !  Really appreciate it.

> extract :: [String] -> [(String,b)] -> ([String],[b])
> extract xs assocs =
>     let xs' = map uppercase xs
>         eithers = map (\x -> lookupEither x assocs) xs'
>         -- spoilers: same as [ lookupEither x assocs | x <- xs' ]
>     in partitionEithers eithers

> 
> This differs slightly from your algorithm in that it returns
> '(["BAR"],[1]), where yours would return (["Bar"],[1]). If preserving
> the original case in the output, I would either write a

ok. big surprise, i like your version much better.
however, i'm unclear why you didn't just use

  eithers = map (\x -> lookupEither (uppercase x) assocs) xs

instead of mapping everything to uppercase first.

meanwhile i need to get with the list comprehension program.  i use python list comprehensions all the time, and yet i continue to use map in haskell. how weird is that ?


Brian


More information about the Beginners mailing list