1

如果我想将Ints 的列表转换为[1,2,3]to ["∧","∨","→"](因此,如果有 '1' 将其转换为 '∧' 等...),我会怎么做

4

1 回答 1

8

我可能会分两步完成:

conv :: Int -> String
conv 1 = "∧"
conv 2 = "∨"
conv 3 = "→"

然后只是映射:

change :: [Int] -> [String]
change = map conv

change [1,2,3] -- returns ["∧","∨","→"]

你甚至可以嵌入:

change = map conv
  where
    conv 1 = "∧"
    ...
于 2013-04-15T15:13:14.423 回答