[Haskell-cafe] list comprehension with multiple generator|targets

Raphaël Mongeau raphaelsimeon at gmail.com
Mon Nov 10 03:10:59 UTC 2014


I don't think list comprehension is the solution. What you want is a map.

Would this work?


data V = A | B | C

f :: [V] -> String
f l = flip map l $ \x -> case x of
    A -> 'A'
    B -> 'B'
    C -> 'C'

main = print $ f [A,B,C,C,A]

2014-11-09 21:58 GMT-05:00 Donn Cave <donn at avvanta.com>:

> I'm guessing this isn't supported, but might be worth asking -
> can I extend a list comprehension like  ['A' | A <- s] to multiple values?
> Like,
>
> data V = A | B | C
>
> pv :: [V] -> [Char]
> pv [] = []
> pv (A:x) = 'A':(pv x)
> pv (B:x) = 'B':(pv x)
> pv (_:x) = pv x
>
> -- can that be a list comprehension, like
>
> pv s = [
>           'A' | A <- s
>           -- ??
>           ]
>
> thanks,
>         Donn
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Viva Cila
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141109/69f8da79/attachment.html>


More information about the Haskell-Cafe mailing list