{-# LANGUAGE TemplateHaskell #-}
module Language.Drasil.Chunk.Unitary (
Unitary(..), UnitaryChunk,
mkUnitary, unitary, unitary', unit_symb) where
import Language.Drasil.Symbol
import Language.Drasil.Classes (NamedIdea(term), Idea(getA),
IsUnit, usymb, Quantity)
import Language.Drasil.Chunk.Quantity (QuantityDict, mkQuant, mkQuant', qw)
import Language.Drasil.UnitLang (USymb)
import Language.Drasil.Chunk.UnitDefn (MayHaveUnit(getUnit), UnitDefn, unitWrapper)
import Language.Drasil.Space (Space, HasSpace(..))
import Language.Drasil.Stages (Stage)
import Language.Drasil.NounPhrase.Core (NP)
import Language.Drasil.UID (HasUID(..))
import Control.Lens ((^.), makeLenses)
class (Quantity c) => Unitary c where
unit :: c -> UnitDefn
data UnitaryChunk = UC { UnitaryChunk -> QuantityDict
_quant :: QuantityDict
, UnitaryChunk -> UnitDefn
_un :: UnitDefn
}
makeLenses ''UnitaryChunk
instance HasUID UnitaryChunk where uid :: Lens' UnitaryChunk UID
uid = Lens' UnitaryChunk QuantityDict
quant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance NamedIdea UnitaryChunk where term :: Lens' UnitaryChunk NP
term = Lens' UnitaryChunk QuantityDict
quant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. NamedIdea c => Lens' c NP
term
instance Idea UnitaryChunk where getA :: UnitaryChunk -> Maybe String
getA UnitaryChunk
uc = forall c. Idea c => c -> Maybe String
getA forall a b. (a -> b) -> a -> b
$ UnitaryChunk
uc forall s a. s -> Getting a s a -> a
^. Lens' UnitaryChunk QuantityDict
quant
instance HasSpace UnitaryChunk where typ :: Getter UnitaryChunk Space
typ = Lens' UnitaryChunk QuantityDict
quant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasSpace c => Getter c Space
typ
instance HasSymbol UnitaryChunk where symbol :: UnitaryChunk -> Stage -> Symbol
symbol UnitaryChunk
u = forall c. HasSymbol c => c -> Stage -> Symbol
symbol (UnitaryChunk
uforall s a. s -> Getting a s a -> a
^.Lens' UnitaryChunk QuantityDict
quant)
instance Quantity UnitaryChunk where
instance Unitary UnitaryChunk where unit :: UnitaryChunk -> UnitDefn
unit UnitaryChunk
x = UnitaryChunk
x forall s a. s -> Getting a s a -> a
^. Lens' UnitaryChunk UnitDefn
un
instance MayHaveUnit UnitaryChunk where getUnit :: UnitaryChunk -> Maybe UnitDefn
getUnit UnitaryChunk
u = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ UnitaryChunk
u forall s a. s -> Getting a s a -> a
^. Lens' UnitaryChunk UnitDefn
un
unitary :: (IsUnit u) => String -> NP -> Symbol -> u -> Space -> UnitaryChunk
unitary :: forall u.
IsUnit u =>
String -> NP -> Symbol -> u -> Space -> UnitaryChunk
unitary String
i NP
t Symbol
s u
u Space
space = QuantityDict -> UnitDefn -> UnitaryChunk
UC (String
-> NP
-> Symbol
-> Space
-> Maybe UnitDefn
-> Maybe String
-> QuantityDict
mkQuant String
i NP
t Symbol
s Space
space (forall a. a -> Maybe a
Just UnitDefn
uu) forall a. Maybe a
Nothing) UnitDefn
uu
where uu :: UnitDefn
uu = forall u. IsUnit u => u -> UnitDefn
unitWrapper u
u
unitary' :: (IsUnit u) => String -> NP -> (Stage -> Symbol) -> u -> Space -> UnitaryChunk
unitary' :: forall u.
IsUnit u =>
String -> NP -> (Stage -> Symbol) -> u -> Space -> UnitaryChunk
unitary' String
i NP
t Stage -> Symbol
s u
u Space
space = QuantityDict -> UnitDefn -> UnitaryChunk
UC (String
-> NP
-> Maybe String
-> Space
-> (Stage -> Symbol)
-> Maybe UnitDefn
-> QuantityDict
mkQuant' String
i NP
t forall a. Maybe a
Nothing Space
space Stage -> Symbol
s (forall a. a -> Maybe a
Just UnitDefn
uu)) UnitDefn
uu
where uu :: UnitDefn
uu = forall u. IsUnit u => u -> UnitDefn
unitWrapper u
u
mkUnitary :: (Unitary u, MayHaveUnit u) => u -> UnitaryChunk
mkUnitary :: forall u. (Unitary u, MayHaveUnit u) => u -> UnitaryChunk
mkUnitary u
u = QuantityDict -> UnitDefn -> UnitaryChunk
UC (forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw u
u) (forall c. Unitary c => c -> UnitDefn
unit u
u)
unit_symb :: (Unitary c) => c -> USymb
unit_symb :: forall c. Unitary c => c -> USymb
unit_symb c
c = forall u. HasUnitSymbol u => u -> USymb
usymb forall a b. (a -> b) -> a -> b
$ forall c. Unitary c => c -> UnitDefn
unit c
c