Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tim Steenvoorden
clean-base
Commits
519b15aa
Commit
519b15aa
authored
Feb 06, 2016
by
Tim Steenvoorden
Browse files
implement Lattice for Int and Nat
parent
9e792843
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/Data/Int.dcl
View file @
519b15aa
definition
module
Data
.
Int
from
Algebra
.
Order
import
class
Eq
,
class
Ord
from
Algebra
.
Enum
import
class
Enum
from
Algebra
.
Group
import
class
Semigroup
,
class
Monoid
,
class
Group
from
Algebra
.
Ring
import
class
Semiring
,
class
Ring
,
class
Domain
from
Algebra
.
Enum
import
class
Enum
from
Algebra
.
Lattice
import
class
MeetSemilattice
,
class
JoinSemilattice
,
class
UpperBounded
,
class
LowerBounded
/// # Definition
...
...
@@ -23,6 +24,11 @@ instance Semiring Int
// instance Ring Int
instance
Domain
Int
instance
MeetSemilattice
Int
instance
JoinSemilattice
Int
instance
UpperBounded
Int
instance
LowerBounded
Int
/// # Helpers
inc
::
!
Int
->
Int
...
...
src/Data/Int.icl
View file @
519b15aa
...
...
@@ -3,9 +3,10 @@ implementation module Data.Int
import
Control
.
Function
import
Algebra
.
Order
import
Algebra
.
Enum
import
Algebra
.
Group
import
Algebra
.
Ring
import
Algebra
.
Enum
import
Algebra
.
Lattice
import
Clean
.
Prim
...
...
@@ -62,6 +63,7 @@ instance Monoid Int where
instance
Group
Int
where
(-)
x
y
=
prim_subInt
x
y
inverse
x
=
prim_negInt
x
instance
Semiring
Int
where
...
...
@@ -86,6 +88,18 @@ instance Domain Int where
lcm
0
_
=
0
lcm
x
y
=
abs
((
x
`
quot`
gcd
x
y
)
*
y
)
instance
MeetSemilattice
Int
where
(/\)
x
y
=
prim_minInt
x
y
instance
JoinSemilattice
Int
where
(\/)
x
y
=
prim_maxInt
x
y
instance
UpperBounded
Int
where
top
=
undefined
instance
LowerBounded
Int
where
bottom
=
undefined
/// # Helpers
inc
::
!
Int
->
Int
...
...
src/Data/Nat.dcl
View file @
519b15aa
...
...
@@ -2,7 +2,8 @@ definition module Data.Nat
from
Algebra
.
Order
import
class
Eq
,
class
Ord
from
Algebra
.
Group
import
class
Semigroup
,
class
Monoid
from
Algebra
.
Ring
import
class
Semiring
from
Algebra
.
Ring
import
class
Semiring
,
class
Domain
from
Algebra
.
Lattice
import
class
MeetSemilattice
,
class
JoinSemilattice
,
class
UpperBounded
,
class
LowerBounded
/// # Definition
...
...
@@ -20,6 +21,11 @@ instance Semigroup Nat
instance
Monoid
Nat
instance
Semiring
Nat
instance
MeetSemilattice
Nat
instance
JoinSemilattice
Nat
instance
UpperBounded
Nat
instance
LowerBounded
Nat
/// # Special Algebra
(.-)
infixl
6
::
!
Nat
!
Nat
->
Nat
src/Data/Nat.icl
View file @
519b15aa
...
...
@@ -7,6 +7,7 @@ import Control.Function
import
Algebra
.
Order
import
Algebra
.
Group
import
Algebra
.
Ring
import
Algebra
.
Lattice
import
Clean
.
Prim
...
...
@@ -17,8 +18,8 @@ import Clean.Prim
//TODO rewrite in inlined ABC (?)
nat
::
!
Int
->
Nat
nat
n
|
prim_ltInt
n
0
=
abort
"Data.Nat.nat: negative integer"
|
otherwise
=
n
|
n
<
0
=
prim_
abort
"Data.Nat.nat: negative integer"
|
otherwise
=
n
int
::
!
Nat
->
Int
int
n
=
prim_noop
...
...
@@ -48,10 +49,25 @@ instance Semiring Nat where
unity
=
prim_oneInt
/// ## Lattice
instance
MeetSemilattice
Nat
where
(/\)
x
y
=
prim_minInt
x
y
instance
JoinSemilattice
Nat
where
(\/)
x
y
=
prim_maxInt
x
y
instance
UpperBounded
Nat
where
top
=
prim_upperInt
instance
LowerBounded
Nat
where
bottom
=
prim_zeroInt
/// # Special Algebra
//TODO rewrite in inlined ABC (?)
(.-)
infixl
6
::
!
Nat
!
Nat
->
Nat
(.-)
n
m
|
prim_ltInt
m
n
=
prim_subInt
n
m
|
otherwise
=
0
|
m
<
n
=
prim_subInt
n
m
|
otherwise
=
prim_zeroInt
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment