Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6165397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:09:24+00:00 2026-05-23T22:09:24+00:00

I am trying to write elliptic curve point addition using where clause. I am

  • 0

I am trying to write elliptic curve point addition using where clause. I am getting compiler error but when i translated the same code using let in expression , it works fine. Could some one please tell me what is wrong with this code. Full source code [ http://hpaste.org/49174 ]

Thank you

Mukesh Tiwari

{--
--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'

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:09:24+00:00Added an answer on May 23, 2026 at 10:09 pm

    The problem is that where blocks scope over function guards, so it’s not possible to create a separate where for each guarded statement. When ghc encounters the where on line 59, it automatically ends the function declaration and expects a new declaration to follow, which makes the | an error because it’s not a valid declaration. It works with a let-expression because let and where are different parts of the language. The Haskell Wiki has more information on this topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking
Im trying to write an algorithm using the algorithm package, but when I use
In trying to write more testable Java code, I have been using the Model-View-Presenter
I'm trying to write a blog post which includes a code segment inside a
I'm trying write a Ruby script that checks if user credentials are valid using
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
Im trying to write a piece of code to set the image of the
Im trying to write a chat app with the push-model but up to now
I'm trying to write code of timer countdown with javascript, sql , c# ,
I am trying to write a wrapper library for MIDI functions in WinMM.dll, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.