小编Kol*_*ter的帖子

取回原始x:xs

我想在Haskell中创建一个函数,如下所示:

encode :: [(Char,Char)] - > String - > String

我有一个名为"table"的"字典"函数,它创建了一对对列表:

table :: Int -> [Char] -> [(Char, Char)]
table __ [] = []
table n l   = zip l (drop n (cycle l))
Run Code Online (Sandbox Code Playgroud)

encode函数按字符对字符串进行编码.到目前为止它看起来像这样:

encode (x:xs) (n:ns)
| length(n:ns) > 1 && (fst x) == n  = [snd x] ++ (encode (x:xs) ns)
| length(xs) > 1 && (fst x) /= n    = encode xs (n:ns)
| length(ns) > 0 && length(xs) == 0 = encode (x:xs) ns
Run Code Online (Sandbox Code Playgroud)

对于测试, …

haskell return list

1
推荐指数
1
解决办法
155
查看次数

标签 统计

haskell ×1

list ×1

return ×1