module Data.HList.Label3 where
import Data.HList.FakePrelude
import Data.HList.HListPrelude
import GHC.TypeLits
import Data.Typeable
data Lbl (x :: HNat) (ns :: *) (desc :: *)
#if !OLD_TYPEABLE
deriving Typeable
#else
instance (ShowLabel x) => Typeable2 (Lbl x) where
typeOf2 _ = mkTyConApp (mkTyCon3 "HList" "Data.HList.Label3" "Lbl")
[mkTyConApp (mkTyCon3 "GHC" "GHC.TypeLits" (showLabel (Label :: Label x)))
[]]
#endif
type instance ZipTagged (Lbl ix ns n ': ts) (v ': vs) = Tagged (Lbl ix ns n) v ': ZipTagged ts vs
instance (Label t ~ Label (Lbl ix ns n)) => SameLabels (Label t) (Lbl ix ns n)
firstLabel :: ns -> desc -> Label (Lbl HZero ns desc)
firstLabel _ _ = Label
nextLabel :: Label (Lbl x ns desc) -> desc' -> Label (Lbl (HSucc x) ns desc')
nextLabel _ _ = Label
instance Show desc => ShowLabel (Lbl x ns desc) where
showLabel = show . getd
where getd :: Label (Lbl x ns desc) -> desc
getd = error "Data.HList.Label3 desc"
instance Show desc => Show (Label (Lbl x ns desc))
where
show = show . getd
where getd :: Label (Lbl x ns desc) -> desc
getd = error "Data.HList.Label3 desc"
instance HExtend (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' ': xs)) where
type HExtendR (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' ': xs))
= Proxy (Lbl n ns desc ': Lbl n' ns' desc' ': xs)
(.*.) _ _ = Proxy
instance HExtend (Label (Lbl n ns desc)) (Proxy (x ': xs :: [Symbol])) where
type HExtendR (Label (Lbl n ns desc)) (Proxy (x ': xs))
= Proxy (Label (Lbl n ns desc) ': MapLabel (x ': xs))
(.*.) _ _ = Proxy
instance HExtend (Label (y :: Symbol)) (Proxy ((x :: *) ': xs)) where
type HExtendR (Label (y :: Symbol)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
(.*.) _ _ = Proxy
instance HExtend (Label (y :: Symbol)) (Proxy ((x :: Nat) ': xs)) where
type HExtendR (Label (y :: Symbol)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
(.*.) _ _ = Proxy
instance HExtend (Label (y :: Nat)) (Proxy ((x :: *) ': xs)) where
type HExtendR (Label (y :: Nat)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
(.*.) _ _ = Proxy
instance HExtend (Label (y :: Nat)) (Proxy ((x :: Symbol) ': xs)) where
type HExtendR (Label (y :: Nat)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
(.*.) _ _ = Proxy
type family MapLabel (xs :: [k]) :: [*]
type instance MapLabel '[] = '[]
#if NO_CLOSED_TF
type instance MapLabel ((x :: Symbol) ': xs) = Label x ': MapLabel xs
type instance MapLabel (Lbl n ns desc ': xs) = Label (Lbl n ns desc) ': MapLabel xs
type instance MapLabel (Label x ': xs) = Label x ': MapLabel xs
#else
type instance MapLabel (x ': xs) = AddLabel x ': MapLabel xs
type family AddLabel (x :: k) :: * where
AddLabel (Label x) = Label x
AddLabel x = Label x
#endif