{-# LANGUAGE GADTs, DataKinds #-}
{-# LANGUAGE KindSignatures #-}
module Language.Drasil.Space (
Space(..),
RealInterval(..), Inclusive(..),
DomainDesc(..), RTopology(..), DiscreteDomainDesc, ContinuousDomainDesc,
HasSpace(..),
getActorName, getInnerSpace, mkFunction
) where
import qualified Data.List.NonEmpty as NE
import Language.Drasil.Symbol (Symbol)
import Control.Lens (Lens')
data Space =
Integer
| Rational
| Real
| Natural
| Boolean
| Char
| String
| Radians
| Vect Space
| Array Space
| Actor String
| DiscreteD [Double]
| DiscreteS [String]
| Function (NE.NonEmpty Primitive) Primitive
| Void
deriving (Space -> Space -> Bool
(Space -> Space -> Bool) -> (Space -> Space -> Bool) -> Eq Space
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Space -> Space -> Bool
$c/= :: Space -> Space -> Bool
== :: Space -> Space -> Bool
$c== :: Space -> Space -> Bool
Eq, Int -> Space -> ShowS
[Space] -> ShowS
Space -> String
(Int -> Space -> ShowS)
-> (Space -> String) -> ([Space] -> ShowS) -> Show Space
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Space] -> ShowS
$cshowList :: [Space] -> ShowS
show :: Space -> String
$cshow :: Space -> String
showsPrec :: Int -> Space -> ShowS
$cshowsPrec :: Int -> Space -> ShowS
Show)
class HasSpace c where
typ :: Lens' c Space
type Primitive = Space
mkFunction :: [Primitive] -> Primitive -> Space
mkFunction :: [Space] -> Space -> Space
mkFunction [] = String -> Space -> Space
forall a. HasCallStack => String -> a
error "Function space creation requires at least 1 input Space"
mkFunction ins :: [Space]
ins = NonEmpty Space -> Space -> Space
Function ([Space] -> NonEmpty Space
forall a. [a] -> NonEmpty a
NE.fromList [Space]
ins)
data RTopology = Continuous | Discrete
data DomainDesc (tplgy :: RTopology) a b where
BoundedDD :: Symbol -> RTopology -> a -> b -> DomainDesc 'Discrete a b
AllDD :: Symbol -> RTopology -> DomainDesc 'Continuous a b
type DiscreteDomainDesc a b = DomainDesc 'Discrete a b
type ContinuousDomainDesc a b = DomainDesc 'Continuous a b
data Inclusive = Inc | Exc
data RealInterval a b where
Bounded :: (Inclusive, a) -> (Inclusive, b) -> RealInterval a b
UpTo :: (Inclusive, a) -> RealInterval a b
UpFrom :: (Inclusive, b) -> RealInterval a b
getActorName :: Space -> String
getActorName :: Space -> String
getActorName (Actor n :: String
n) = String
n
getActorName _ = ShowS
forall a. HasCallStack => String -> a
error "getActorName called on non-actor space"
getInnerSpace :: Space -> Space
getInnerSpace :: Space -> Space
getInnerSpace (Vect s :: Space
s) = Space
s
getInnerSpace _ = String -> Space
forall a. HasCallStack => String -> a
error "getInnerSpace called on non-vector space"