Search code examples
haskelllist-comprehensionpointfree

how to write a function using list comprehension in haskell?


I've written this function using map, but I need to write this using list comprehension:

alter = map (\x -> if x == 0 then 1 else 0)

it gives e.g.

alter [1,1,0]  
> [0,0,1]

Solution

  • You can't write it point-free using list comprehension:

    alter xs = [if x == 0 then 1 else 0 | x <- xs]