0
我已經寫了使用map
這個功能,但我需要寫這個用list理解:如何用haskell編寫一個使用列表理解的函數?
alter = map (\x -> if x == 0 then 1 else 0)
它給例如
alter [1,1,0]
> [0,0,1]
我已經寫了使用map
這個功能,但我需要寫這個用list理解:如何用haskell編寫一個使用列表理解的函數?
alter = map (\x -> if x == 0 then 1 else 0)
它給例如
alter [1,1,0]
> [0,0,1]
你不能寫點,免費使用列表理解:
alter xs = [if x == 0 then 1 else 0 | x <- xs]