-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Paul Cadman <[email protected]>
- Loading branch information
1 parent
183d4e9
commit e2efe4e
Showing
14 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Stdlib.Data.Field; | ||
|
||
import Stdlib.Data.Field.Base open using {Field} public; | ||
import Stdlib.Data.Field.Base as Field; | ||
import Stdlib.Data.String.Base open; | ||
import Stdlib.Data.Nat; | ||
|
||
import Stdlib.Trait.Eq open public; | ||
import Stdlib.Trait.Show open public; | ||
import Stdlib.Trait.Natural open public; | ||
import Stdlib.Trait.Integral open public; | ||
import Stdlib.Trait.Numeric open public; | ||
|
||
{-# specialize: true, inline: case #-} | ||
instance | ||
eqFieldI : Eq Field := mkEq (Field.==); | ||
|
||
instance | ||
showFieldI : Show Field := | ||
mkShow@{ | ||
show (f : Field) : String := Show.show (Field.toNat f) | ||
}; | ||
|
||
{-# specialize: true, inline: case #-} | ||
instance | ||
naturalFieldI : Natural Field := | ||
mkNatural@{ | ||
+ := (Field.+); | ||
* := (Field.*); | ||
fromNat := Field.fromNat | ||
}; | ||
|
||
{-# specialize: true, inline: case #-} | ||
instance | ||
integralFieldI : Integral Field := | ||
mkIntegral@{ | ||
naturalI := naturalFieldI; | ||
- := (Field.-); | ||
fromInt := Field.fromInt | ||
}; | ||
|
||
{-# specialize: true, inline: case #-} | ||
instance | ||
numericFieldI : Numeric Field := | ||
mkNumeric@{ | ||
integralI := integralFieldI; | ||
/ := (Field./) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Stdlib.Data.Field.Base; | ||
|
||
import Stdlib.Data.Fixity open; | ||
import Stdlib.Data.Nat.Base open; | ||
import Stdlib.Data.Int.Base open hiding {toNat}; | ||
import Stdlib.Data.Bool.Base open; | ||
|
||
builtin field | ||
axiom Field : Type; | ||
|
||
syntax operator + additive; | ||
|
||
builtin field-add | ||
axiom + : Field -> Field -> Field; | ||
|
||
syntax operator - additive; | ||
|
||
builtin field-sub | ||
axiom - : Field -> Field -> Field; | ||
|
||
syntax operator * multiplicative; | ||
|
||
builtin field-mul | ||
axiom * : Field -> Field -> Field; | ||
|
||
syntax operator / multiplicative; | ||
|
||
builtin field-div | ||
axiom / : Field -> Field -> Field; | ||
|
||
syntax operator == comparison; | ||
|
||
builtin field-eq | ||
axiom == : Field -> Field -> Bool; | ||
|
||
builtin field-from-int | ||
axiom fromInt : Int -> Field; | ||
|
||
builtin field-to-nat | ||
axiom toNat : Field -> Nat; | ||
|
||
fromNat (n : Nat) : Field := fromInt (ofNat n); | ||
|
||
toInt (f : Field) : Int := ofNat (toNat f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Stdlib.Trait.DivMod; | ||
|
||
trait | ||
type DivMod A := | ||
mkDivMod { | ||
div : A -> A -> A; | ||
mod : A -> A -> A | ||
}; | ||
|
||
open DivMod public; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Stdlib.Trait.Numeric; | ||
|
||
import Stdlib.Data.Fixity open; | ||
import Stdlib.Trait.Integral open; | ||
|
||
trait | ||
type Numeric A := | ||
mkNumeric { | ||
integralI : Integral A; | ||
syntax operator / multiplicative; | ||
/ : A -> A -> A | ||
}; | ||
|
||
open Numeric using {/} public; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters