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
bd0acdeb
Commit
bd0acdeb
authored
Feb 06, 2016
by
Tim Steenvoorden
Browse files
implement Enum for Int
parent
01480a7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Data/Int.dcl
View file @
bd0acdeb
...
...
@@ -3,6 +3,7 @@ definition module Data.Int
from
Algebra
.
Order
import
class
Eq
,
class
Ord
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
/// # Definition
...
...
@@ -13,6 +14,7 @@ from Algebra.Ring import class Semiring, class Ring, class Domain
instance
Eq
Int
instance
Ord
Int
instance
Enum
Int
instance
Semigroup
Int
instance
Monoid
Int
...
...
@@ -25,4 +27,3 @@ instance Domain Int
inc
::
!
Int
->
Int
dec
::
!
Int
->
Int
src/Data/Int.icl
View file @
bd0acdeb
...
...
@@ -5,12 +5,13 @@ import Control.Function
import
Algebra
.
Order
import
Algebra
.
Group
import
Algebra
.
Ring
import
Algebra
.
Enum
import
Clean
.
Prim
/// # Instances
/// ##
Comparison
/// ##
Order
instance
Eq
Int
where
(==)
x
y
=
prim_eqInt
x
y
...
...
@@ -18,6 +19,39 @@ instance Eq Int where
instance
Ord
Int
where
(<)
x
y
=
prim_ltInt
x
y
instance
Enum
Int
where
toEnum
n
=
prim_noop
fromEnum
n
=
prim_noop
succ
x
=
prim_incInt
x
pred
x
=
prim_decInt
x
//TODO move to class (defaults extension) or instance on Ord Ring (flexibles extension)
enumFrom
x
=
[
x
:
enumFrom
(
succ
x
)]
enumFromTo
x
y
|
x
<=
y
=
[
x
:
enumFromTo
(
succ
x
)
y
]
|
otherwise
=
[]
enumFromThen
x
y
=
[
x
:
enumFromBy
x
(
y
-
x
)]
where
// enumFromBy x s :: Int Int -> .[Int]
enumFromBy
x
s
=
[
x
:
enumFromBy
(
x
+
s
)
s
]
enumFromThenTo
x
y
z
|
x
<=
y
=
enumFromByUpto
x
(
y
-
x
)
z
|
otherwise
=
enumFromByDownto
x
(
x
-
y
)
z
where
// enumFromByUpto :: !Int !Int !Int -> .[Int]
enumFromByUpto
x
s
z
|
x
<=
z
=
[
x
:
enumFromByUpto
(
x
+
s
)
s
z
]
|
otherwise
=
[]
// enumFromByDownto :: !Int !Int !Int -> .[Int]
enumFromByDownto
x
s
z
|
x
>=
z
=
[
x
:
enumFromByDownto
(
x
-
s
)
s
z
]
|
otherwise
=
[]
/// ## Algebra
instance
Semigroup
Int
where
...
...
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