Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 哈斯克尔使用地图_Haskell - Fatal编程技术网

Haskell 哈斯克尔使用地图

Haskell 哈斯克尔使用地图,haskell,Haskell,我想知道是否有可能在我的代码中使用映射,而不是像现在这样。我的代码是接收一个字符串,用其他字符串替换一些字符并将其反转,但我想在这段代码中使用映射 transforme' ::[Char] -> [Char] transforme' = reverse'.condiçoes condiçoes :: [Char] -> [Char] condiçoes = foldr (\x -> if x == 'A' then ('U':)

我想知道是否有可能在我的代码中使用映射,而不是像现在这样。我的代码是接收一个
字符串
,用其他字符串替换一些
字符
并将其反转,但我想在这段代码中使用映射

transforme' ::[Char] -> [Char]
transforme'   = reverse'.condiçoes

condiçoes :: [Char] -> [Char]
condiçoes   = foldr (\x -> if
                x == 'A' then ('U':)
                else if x == 'T' then ('A':)
                else if x == 'C' then ('G':)
                else if x == 'G' then ('C':)
                else (x:)) []

reverse' :: [Char] -> [Char]
reverse' xs = foldr (\b f x -> f (b : x)) id xs []
您可以首先构造一个“翻译”函数:

trns 'A' = 'U'
trns 'T' = 'A'
trns 'C' = 'G'
trns 'G' = 'C'
trns x = x
我们如何使用:

condiçoes = map trns
因此,我们在
trns
函数上执行映射

请注意,有一个内置的,或者您可以为此使用
foldl

reverse' :: [a] -> [a]
reverse' = foldl (flip (:)) []
可能重复的