Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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_Elliptic Curve - Fatal编程技术网

Haskell代码中的编译器错误

Haskell代码中的编译器错误,haskell,elliptic-curve,Haskell,Elliptic Curve,我正在尝试使用where子句编写椭圆曲线点加法。我得到了编译器错误,但当我使用let-in表达式翻译相同的代码时,它工作正常。谁能告诉我这个密码有什么问题吗。完整源代码[] 多谢各位 穆克什·蒂瓦里 {-- --add points of elliptic curve using where clause getting compiler error addPoints :: Elliptic -> Point -> Point -> Either Point Integer

我正在尝试使用where子句编写椭圆曲线点加法。我得到了编译器错误,但当我使用let-in表达式翻译相同的代码时,它工作正常。谁能告诉我这个密码有什么问题吗。完整源代码[]
多谢各位
穆克什·蒂瓦里

{--
--add points of elliptic curve using where clause getting compiler error
addPoints :: Elliptic -> Point -> Point -> Either Point Integer
addPoints _ Identity p_2 = Left p_2
addPoints _ p_1 Identity = Left p_1
addPoints ( Conelliptic a b n ) ( Conpoint x_p y_p ) ( Conpoint x_q y_q )  
    | x_p /= x_q =  case ( ( Conpoint x_r y_r ) , d ) of
                        ( _ , 1 ) -> Left ( Conpoint x_r y_r )
                        ( _ , d' ) -> Right d'
                      where
                                [ u , v , d ] = extended_gcd ( x_p - x_q ) n
                                s = mod ( ( y_p - y_q ) * u ) n
                                x_r = mod ( s*s - x_p - x_q ) n
                                y_r = mod ( -y_p - s * ( x_r - x_p ) ) n
    | otherwise =   if mod ( y_p + y_q ) n == 0 then Left Identity
                     else  case ( ( Conpoint x_r y_r ) , d ) of
                                ( _ , 1 ) -> Left ( Conpoint x_r y_r )
                                ( _ , d' ) -> Right d'
                            where
                                [ u , v , d ] = extended_gcd ( 2 * y_p ) n
                                s = mod ( ( 3 * x_p * x_p + a ) * u ) n
                                x_r = mod ( s * s - 2 * x_p ) n
                                y_r = mod ( -y_p - s * ( x_r - x_p ) ) n 

--}


--add points of elliptic curve let in clause and its working
addPoints::Elliptic->Point->Point-> Either Point Integer
addPoints _ Identity p_2 = Left p_2
addPoints _ p_1 Identity = Left p_1
addPoints ( Conelliptic a b n ) ( Conpoint x_p y_p ) ( Conpoint x_q y_q )
| x_p /= x_q = let
           [ u , v , d ] = extended_gcd (x_p-x_q) n
           s = mod  ( ( y_p - y_q ) * u ) n
           x_r = mod ( s * s - x_p - x_q ) n
           y_r= mod ( -y_p - s * ( x_r - x_p ) ) n
         in case ( ( Conpoint x_r y_r ) , d ) of
          ( _ , 1 ) -> Left ( Conpoint x_r y_r )
          ( _ , d' ) -> Right d'
| otherwise = if mod ( y_p + y_q ) n == 0 then Left Identity
         else  let
              [ u , v , d ] = extended_gcd ( 2*y_p ) n
              s = mod  ( ( 3 * x_p * x_p + a ) * u ) n
              x_r = mod ( s * s - 2 * x_p ) n
              y_r = mod ( -y_p - s * ( x_r - x_p ) ) n
           in case ( ( Conpoint x_r y_r ) , d ) of
                            ( _ , 1 )-> Left (Conpoint x_r y_r)
                            ( _ , d' ) -> Right d'

问题在于
where
阻塞了函数保护的作用域,因此不可能为每个保护语句创建单独的
where
。当ghc在第59行遇到
where
时,它会自动结束函数声明,并期望随后出现新的声明,这使得
|
成为错误,因为它不是有效的声明。它与let表达式一起工作,因为
let
where
是语言的不同部分。有关于此主题的更多信息。

您能发布编译器错误吗?这将对那些想帮助你的人非常有帮助。我找不到错误。两种方法(第一种和第二种)在我的机器上编译都没有问题。(使用GHC 7)椭圆曲线长度。hs:59:8:输入“|”的解析错误失败,加载的模块:无。ghc-6.12.1是从hpaste复制的版本I。请仔细检查它是否和你的一样。此类错误可能与使用制表符而不是空格有关。@fuzzxl是的,但在此代码中,addPoint函数是let in子句,该子句工作正常。尝试使用where子句取消addPoint函数的注释。相同的编译器错误