{-# LANGUAGE CPP #-}
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 :: ns -> desc -> Label (Lbl 'HZero ns desc)
firstLabel ns
_ desc
_ = Label (Lbl 'HZero ns desc)
forall k (l :: k). Label l
Label
nextLabel :: Label (Lbl x ns desc) -> desc' -> Label (Lbl (HSucc x) ns desc')
nextLabel :: Label (Lbl x ns desc) -> desc' -> Label (Lbl ('HSucc x) ns desc')
nextLabel Label (Lbl x ns desc)
_ desc'
_ = Label (Lbl ('HSucc x) ns desc')
forall k (l :: k). Label l
Label
instance Show desc => ShowLabel (Lbl x ns desc) where
showLabel :: Label (Lbl x ns desc) -> String
showLabel = desc -> String
forall a. Show a => a -> String
show (desc -> String)
-> (Label (Lbl x ns desc) -> desc)
-> Label (Lbl x ns desc)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Label (Lbl x ns desc) -> desc
getd
where getd :: Label (Lbl x ns desc) -> desc
getd :: Label (Lbl x ns desc) -> desc
getd = String -> Label (Lbl x ns desc) -> desc
forall a. HasCallStack => String -> a
error String
"Data.HList.Label3 desc"
instance Show desc => Show (Label (Lbl x ns desc))
where
show :: Label (Lbl x ns desc) -> String
show = desc -> String
forall a. Show a => a -> String
show (desc -> String)
-> (Label (Lbl x ns desc) -> desc)
-> Label (Lbl x ns desc)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Label (Lbl x ns desc) -> desc
getd
where getd :: Label (Lbl x ns desc) -> desc
getd :: Label (Lbl x ns desc) -> desc
getd = String -> Label (Lbl x ns desc) -> desc
forall a. HasCallStack => String -> a
error String
"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)
.*. :: Label (Lbl n ns desc)
-> Proxy (Lbl n' ns' desc' : xs)
-> HExtendR (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' : xs))
(.*.) Label (Lbl n ns desc)
_ Proxy (Lbl n' ns' desc' : xs)
_ = HExtendR (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' : xs))
forall k (t :: k). Proxy t
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))
.*. :: Label (Lbl n ns desc)
-> Proxy (x : xs)
-> HExtendR (Label (Lbl n ns desc)) (Proxy (x : xs))
(.*.) Label (Lbl n ns desc)
_ Proxy (x : xs)
_ = HExtendR (Label (Lbl n ns desc)) (Proxy (x : xs))
forall k (t :: k). Proxy t
Proxy
instance HExtend (Label (y :: Symbol)) (Proxy ((x :: *) ': xs)) where
type HExtendR (Label (y :: Symbol)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
.*. :: Label y -> Proxy (x : xs) -> HExtendR (Label y) (Proxy (x : xs))
(.*.) Label y
_ Proxy (x : xs)
_ = HExtendR (Label y) (Proxy (x : xs))
forall k (t :: k). Proxy t
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)))
.*. :: Label y -> Proxy (x : xs) -> HExtendR (Label y) (Proxy (x : xs))
(.*.) Label y
_ Proxy (x : xs)
_ = HExtendR (Label y) (Proxy (x : xs))
forall k (t :: k). Proxy t
Proxy
instance HExtend (Label (y :: Nat)) (Proxy ((x :: *) ': xs)) where
type HExtendR (Label (y :: Nat)) (Proxy (x ': xs))
= Proxy (Label y ': (MapLabel (x ': xs)))
.*. :: Label y -> Proxy (x : xs) -> HExtendR (Label y) (Proxy (x : xs))
(.*.) Label y
_ Proxy (x : xs)
_ = HExtendR (Label y) (Proxy (x : xs))
forall k (t :: k). Proxy t
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)))
.*. :: Label y -> Proxy (x : xs) -> HExtendR (Label y) (Proxy (x : xs))
(.*.) Label y
_ Proxy (x : xs)
_ = HExtendR (Label y) (Proxy (x : xs))
forall k (t :: k). Proxy t
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