module Language.Drasil.UnitLang (
USymb(US), UDefn(..), UnitSymbol(BaseSI, DerivedSI, Defined)
, fromUDefn, compUSymb, getUSymb, getDefn
) where
import Language.Drasil.Symbol (Symbol, compsy)
newtype USymb = US [(Symbol, Integer)]
deriving (USymb -> USymb -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: USymb -> USymb -> Bool
$c/= :: USymb -> USymb -> Bool
== :: USymb -> USymb -> Bool
$c== :: USymb -> USymb -> Bool
Eq)
data UDefn = USynonym USymb
| UScale Double USymb
| UShift Double USymb
fromUDefn :: UDefn -> USymb
fromUDefn :: UDefn -> USymb
fromUDefn (USynonym USymb
x) = USymb
x
fromUDefn (UScale Double
_ USymb
s) = USymb
s
fromUDefn (UShift Double
_ USymb
s) = USymb
s
compUSymb :: USymb -> USymb -> Ordering
compUSymb :: USymb -> USymb -> Ordering
compUSymb (US [(Symbol, Integer)]
l) (US [(Symbol, Integer)]
m) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall a. Monoid a => a -> a -> a
mappend Ordering
EQ forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {a}. Ord a => (Symbol, a) -> (Symbol, a) -> Ordering
comp [(Symbol, Integer)]
l [(Symbol, Integer)]
m
where
comp :: (Symbol, a) -> (Symbol, a) -> Ordering
comp (Symbol
s1, a
i1) (Symbol
s2, a
i2) = Symbol -> Symbol -> Ordering
compsy Symbol
s1 Symbol
s2 forall a. Monoid a => a -> a -> a
`mappend` forall a. Ord a => a -> a -> Ordering
compare a
i1 a
i2
data UnitSymbol =
BaseSI USymb
| DerivedSI USymb USymb UDefn
| Defined USymb UDefn
getUSymb :: UnitSymbol -> USymb
getUSymb :: UnitSymbol -> USymb
getUSymb (BaseSI USymb
u) = USymb
u
getUSymb (DerivedSI USymb
u USymb
_ UDefn
_) = USymb
u
getUSymb (Defined USymb
u UDefn
_) = USymb
u
getDefn :: UnitSymbol -> Maybe UDefn
getDefn :: UnitSymbol -> Maybe UDefn
getDefn (BaseSI USymb
_) = forall a. Maybe a
Nothing
getDefn (DerivedSI USymb
_ USymb
_ UDefn
d) = forall a. a -> Maybe a
Just UDefn
d
getDefn (Defined USymb
_ UDefn
d) = forall a. a -> Maybe a
Just UDefn
d