Commit bd0acdeb authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

implement Enum for Int

parent 01480a7c
......@@ -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
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment