--A function to convet smaller case characters into upper case
convert :: [Char] -> [Char]
convert = map toUpper
--A function to remove all the numbers from a string
noNumber :: [Char] -> [Char]
noNumber = filter isLetter
我想在呼叫以下函式之前添加這些檢查
encode :: [Char] -> [Char] -> [Char]
encode [] ps = []
encode ks [] = []
encode (k:ks) (p:ps) = chr (65 mod (ord k ord p) 26) : encode (ks [k]) ps
這樣我就可以從文本中洗掉任何數字或小寫字符
uj5u.com熱心網友回復:
您可以使用輔助函式:
encode :: [Char] -> [Char] -> [Char]
encode xs ys = go (cycle (f xs)) (f ys)
where go [] ps = []
go ks [] = []
go (k:ks) (p:ps) = chr (65 mod (ord k ord p) 26) : encode ks ps
f = noNumber . convert
那么go只是一個zipWith:
encode :: [Char] -> [Char] -> [Char]
encode xs ys = zipWith g (cycle (f xs)) (f ys)
where g k p = chr (65 mod (ord k ord p) 26)
f = noNumber . convert
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/532475.html
標籤:哈斯克尔
上一篇:使用遞回方案的格路徑演算法
下一篇:如何在qtcpp中播放gif?
