我想要一个带有签名 :: [(Int,Char)] -> [String] 的函数,它接受每个 Char 并根据相应对中的整数值将它们组合成一个字符串列表......
IE。
[(0,'A'),(1,'B'),(2,'C'),(3,'D'),(0,'E'),(1,'F'),(2,'G'),(3,'H'),(0,'I'),(1,'J'),(2,'K'),(3,'L'),(0,'M'),(1,'N'),(2,'O'),(3,'P')]
应该生成列表:["MIEA","NJFB","OKGC","PLHD"]
我试过了:
toList :: [(Int,Char)] -> Int -> [String]
toList [] a = []
toList (x:xs) a = [snd(x) | n <-[0..(a-1)], fst(x) == n]:toList xs a
但这只是给了我:
["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"]
任何建议将不胜感激。