Skip to content

Commit

Permalink
Refactor module exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Multramate committed Aug 9, 2019
1 parent 2b4c21c commit a795eff
Show file tree
Hide file tree
Showing 100 changed files with 1,873 additions and 3,779 deletions.
24 changes: 2 additions & 22 deletions generate/Generate/Binary/Curve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,8 @@ prettyImports :: Types -> Doc
prettyImports Types{..}
= "module Curve.Binary." <> pretty curve
<$$> indent 2
( "( BCurve(..)"
<$$> ", BPoint"
<$$> ", BACurve(..)"
<$$> ", BAPoint"
<$$> ", BPCurve(..)"
<$$> ", BPPoint"
<$$> ", Curve(..)"
<$$> "," <+> prettyField field
<$$> ", Fr"
<$$> ", Group(..)"
<$$> ", PA"
<$$> ", PP"
<$$> ", Point(..)"
<$$> ", _a"
<$$> ", _b"
<$$> ", _h"
<$$> ", _p"
<$$> ", _r"
<$$> ", _x"
<$$> ", _y"
<$$> ", gA"
<$$> ", gP"
( "( module Curve.Binary"
<$$> ", module Curve.Binary." <> pretty curve
<$$> ") where"
)
<> prettyBreak
Expand Down
7 changes: 2 additions & 5 deletions generate/Generate/Binary/Types.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Generate.Binary.Types
( Curve(..)
, Element(..)
, Field(..)
, Parameters(..)
, Types(..)
( module Generate.Binary.Types
, module Generate.Types
) where

import Protolude
Expand Down
5 changes: 1 addition & 4 deletions generate/Generate/Curve.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module Generate.Curve
( prettyElement
, prettyField
, prettyImport
, prettyType
( module Generate.Curve
) where

import Protolude
Expand Down
24 changes: 2 additions & 22 deletions generate/Generate/Edwards/Curve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,8 @@ prettyImports :: Types -> Doc
prettyImports Types{..}
= "module Curve.Edwards." <> pretty curve
<$$> indent 2
( "( Curve(..)"
<$$> ", ECurve(..)"
<$$> ", EPoint"
<$$> ", EACurve(..)"
<$$> ", EAPoint"
<$$> ", EPCurve(..)"
<$$> ", EPPoint"
<$$> "," <+> prettyField field
<$$> ", Fr"
<$$> ", Group(..)"
<$$> ", PA"
<$$> ", PP"
<$$> ", Point(..)"
<$$> ", _a"
<$$> ", _d"
<$$> ", _h"
<$$> ", _q"
<$$> ", _r"
<$$> ", _x"
<$$> ", _y"
<$$> ", gA"
<$$> ", gP"
( "( module Curve.Edwards"
<$$> ", module Curve.Edwards." <> pretty curve
<$$> ") where"
)
<> prettyBreak
Expand Down
7 changes: 2 additions & 5 deletions generate/Generate/Edwards/Types.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Generate.Edwards.Types
( Curve(..)
, Element(..)
, Field(..)
, Parameters(..)
, Types(..)
( module Generate.Edwards.Types
, module Generate.Types
) where

import Protolude
Expand Down
3 changes: 1 addition & 2 deletions generate/Generate/Generate.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Generate.Generate
( prettyElement
, prettyField
( module Generate.Generate
) where

import Protolude
Expand Down
20 changes: 2 additions & 18 deletions generate/Generate/Montgomery/Curve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,8 @@ prettyImports :: Types -> Doc
prettyImports Types{..}
= "module Curve.Montgomery." <> pretty curve
<$$> indent 2
( "( Curve(..)"
<$$> "," <+> prettyField field
<$$> ", Fr"
<$$> ", Group(..)"
<$$> ", MCurve(..)"
<$$> ", MPoint"
<$$> ", MACurve(..)"
<$$> ", MAPoint"
<$$> ", PA"
<$$> ", Point(..)"
<$$> ", _a"
<$$> ", _b"
<$$> ", _h"
<$$> ", _q"
<$$> ", _r"
<$$> ", _x"
<$$> ", _y"
<$$> ", gA"
( "( module Curve.Montgomery"
<$$> ", module Curve.Montgomery." <> pretty curve
<$$> ") where"
)
<> prettyBreak
Expand Down
7 changes: 2 additions & 5 deletions generate/Generate/Montgomery/Types.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Generate.Montgomery.Types
( Curve(..)
, Element(..)
, Field(..)
, Parameters(..)
, Types(..)
( module Generate.Montgomery.Types
, module Generate.Types
) where

import Protolude
Expand Down
10 changes: 2 additions & 8 deletions generate/Generate/Pretty.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
module Generate.Pretty
( prettyBreak
, prettyDocumentation
, prettyInline
, prettyInteger
, prettyLine
, prettySection
, prettyText
( module Generate.Pretty
) where

import Protolude
Expand All @@ -27,7 +21,7 @@ prettyDocumentation

prettyInline :: Doc -> Doc
prettyInline
= braces . enclose "-# INLINE " " #-"
= braces . enclose "-# INLINABLE " " #-"

prettyInteger :: Integer -> Doc
prettyInteger
Expand Down
4 changes: 1 addition & 3 deletions generate/Generate/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module Generate.Types
( Element(..)
, Field(..)
, Types(..)
( module Generate.Types
) where

import Protolude
Expand Down
28 changes: 2 additions & 26 deletions generate/Generate/Weierstrass/Curve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,8 @@ prettyImports :: Types -> Doc
prettyImports Types{..}
= "module Curve.Weierstrass." <> pretty curve
<$$> indent 2
( "( Curve(..)"
<$$> "," <+> prettyField field
<$$> ", Fr"
<$$> ", Group(..)"
<$$> ", PA"
<$$> ", PJ"
<$$> ", PP"
<$$> ", Point(..)"
<$$> ", WCurve(..)"
<$$> ", WPoint"
<$$> ", WACurve(..)"
<$$> ", WAPoint"
<$$> ", WJCurve(..)"
<$$> ", WJPoint"
<$$> ", WPCurve(..)"
<$$> ", WPPoint"
<$$> ", _a"
<$$> ", _b"
<$$> ", _h"
<$$> ", _q"
<$$> ", _r"
<$$> ", _x"
<$$> ", _y"
<$$> ", gA"
<$$> ", gJ"
<$$> ", gP"
( "( module Curve.Weierstrass"
<$$> ", module Curve.Weierstrass." <> pretty curve
<$$> ") where"
)
<> prettyBreak
Expand Down
7 changes: 2 additions & 5 deletions generate/Generate/Weierstrass/Types.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Generate.Weierstrass.Types
( Curve(..)
, Element(..)
, Field(..)
, Parameters(..)
, Types(..)
( module Generate.Weierstrass.Types
, module Generate.Types
) where

import Protolude
Expand Down
16 changes: 7 additions & 9 deletions src/Curve.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Curve
( Coordinates(..)
, Curve(..)
, Form(..)
, Group(..)
( module Curve
, module Group
) where

import Protolude
Expand Down Expand Up @@ -42,7 +40,7 @@ class (GaloisField q, GaloisField r, Group (Point f c e q r))
-- | Curve point multiplication.
mul :: r ~ PrimeField p => Point f c e q r -> r -> Point f c e q r
mul = (. toInt) . mul'
{-# INLINE mul #-}
{-# INLINABLE mul #-}

-- | Get point from X and Y coordinates.
point :: q -> q -> Maybe (Point f c e q r)
Expand Down Expand Up @@ -80,26 +78,26 @@ data Coordinates = Affine
instance Curve f c e q r => Monoid (Point f c e q r) where

mempty = id
{-# INLINE mempty #-}
{-# INLINABLE mempty #-}

-- Elliptic curve points are semigroups.
instance Curve f c e q r => Semigroup (Point f c e q r) where

p <> q = if p == q then dbl p else add p q
{-# INLINE (<>) #-}
{-# INLINABLE (<>) #-}

-- Elliptic curve points are arbitrary.
instance Curve f c e q r => Arbitrary (Point f c e q r) where

arbitrary = suchThatMap arbitrary pointX
{-# INLINE arbitrary #-}
{-# INLINABLE arbitrary #-}

-- Elliptic curve points are random.
instance Curve f c e q r => Random (Point f c e q r) where

random g = let (x, g') = random g in case pointX x of
Just p -> (p, g')
_ -> random g'
{-# INLINE random #-}
{-# INLINABLE random #-}

randomR = panic "not implemented."
Loading

0 comments on commit a795eff

Please sign in to comment.