{-# LANGUAGE DataKinds, PolyKinds, TypeFamilies, TypeOperators, UndecidableInstances,
CPP #-}
#if __GLASGOW_HASKELL__ >= 900
{-# OPTIONS_GHC -Wno-star-is-type #-}
#endif
module Data.Metrology.LCSU (
LCSU(DefaultLCSU), DefaultUnitOfDim,
Lookup, LookupList, MkLCSU
) where
import Data.Metrology.Factor
data LCSU star = MkLCSU_ [(star, star)]
| DefaultLCSU
type family Lookup (dim :: *) (lcsu :: LCSU *) :: * where
Lookup dim (MkLCSU_ ('(dim, unit) ': rest)) = unit
Lookup dim (MkLCSU_ ('(other, u) ': rest)) = Lookup dim (MkLCSU_ rest)
Lookup dim DefaultLCSU = DefaultUnitOfDim dim
type family LookupList (keys :: [Factor *]) (map :: LCSU *) :: [Factor *] where
LookupList '[] lcsu = '[]
LookupList (F dim z ': rest) lcsu
= F (Lookup dim lcsu) z ': LookupList rest lcsu
type family DefaultUnitOfDim (dim :: *) :: *
type family MkLCSU pairs where
MkLCSU pairs = MkLCSU_ (UsePromotedTuples pairs)
type family UsePromotedTuples pairs where
UsePromotedTuples '[] = '[]
UsePromotedTuples ((dim, unit) ': rest) = ('(dim, unit) ': UsePromotedTuples rest)