Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.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,我正在HASKELL中创建函数加密。这就是我目前所拥有的 encipher :: Eq a => [a] -> [b] -> [a] -> [b] encipher _ _ [] = [] encipher xs ys (z:zs) = if f == [] then z:encipher xs ys zs else snd (head f) : (encipher xs ys zs) where t

我正在HASKELL中创建函数加密。这就是我目前所拥有的

encipher :: Eq a => [a] -> [b] -> [a] -> [b]
encipher _ _ [] = []
encipher xs ys (z:zs) = if f == []
                then z:encipher xs ys zs
                else snd (head f) : (encipher xs ys zs)
    where t = zip xs ys
    f = filter ((== z) . fst) t
    

p9tests = [encipher ['A'..'Z'] ['a'..'z'] "THIS" == "this"]

我用p9tests测试它。不确定我做错了什么。

你的问题是缩进。
下的所有定义,其中
需要在同一级别缩进

因此,为了修复您的特定错误,您可以将
f
缩进到上面一行的
t
级别:

    where t = zip xs ys
          f = filter ((== z) . fst) t
或者你可以走另一条路,把
t
带到
f
的级别:

    where 
    t = zip xs ys
    f = filter ((== z) . fst) t

你的问题是什么?我得到了一个错误。我在f=filter(==z)上得到了一个错误。fst)t输入上的一个错误'f'是我得到的错误。我修复了这个错误,但仍然得到了错误。如果你有不同的错误,请发布不同的问题。另外,如果你遇到了一个错误,最好告诉帮助你的人这个错误到底是什么,这样他们就不用猜了。