module Goal.Geometry.Set
(
Set
, Element
, Discrete (elements)
, Boolean (Boolean)
, NaturalNumbers (NaturalNumbers)
, Integers (Integers)
, Coordinates
, Euclidean (Euclidean)
, Continuum (Continuum)
, Replicated (Replicated)
) where
import Goal.Core
import qualified Data.Vector.Storable as C
class (Eq s, Eq (Element s)) => Set s where
type Element s :: *
class Set s => Discrete s where
elements :: s -> [Element s]
data NaturalNumbers = NaturalNumbers deriving (Eq,Read,Show)
data Integers = Integers deriving (Eq,Read,Show)
data Boolean = Boolean deriving (Eq,Read,Show)
newtype Euclidean = Euclidean Int deriving (Eq,Read,Show)
data Continuum = Continuum deriving (Eq,Read,Show)
type Coordinates = C.Vector Double
data Replicated m = Replicated !m !Int deriving (Eq,Read,Show)
instance Set NaturalNumbers where
type Element NaturalNumbers = Int
instance Discrete NaturalNumbers where
elements _ = [0..]
instance Set Integers where
type Element Integers = Int
instance Discrete Integers where
elements _ = (0:) $ concat [ [k,k] | k <- [1..] ]
instance Set Boolean where
type Element Boolean = Bool
instance Discrete Boolean where
elements _ = [True,False]
instance Eq k => Set [k] where
type Element [k] = k
instance Eq k => Discrete [k] where
elements = id
instance Set Continuum where
type Element Continuum = Double
instance Set Euclidean where
type Element Euclidean = Coordinates
instance Set s => Set (Replicated s) where
type Element (Replicated s) = [Element s]
instance Discrete s => Discrete (Replicated s) where
elements (Replicated s n) = replicateM n $ elements s
instance (Set s, Set r) => Set (s,r) where
type Element (s,r) = (Element s,Element r)