{-# LANGUAGE DataKinds #-}
module Choreography.Location where
import Data.Proxy
import Data.String
import GHC.TypeLits
import Language.Haskell.TH
type LocTm = String
type LocTy = Symbol
toLocTm :: forall (l :: LocTy). KnownSymbol l => Proxy l -> LocTm
toLocTm :: forall (l :: LocTy). KnownSymbol l => Proxy l -> LocTm
toLocTm = forall (n :: LocTy) (proxy :: LocTy -> *).
KnownSymbol n =>
proxy n -> LocTm
symbolVal
data a @ (l :: LocTy)
= Wrap a
| Empty
wrap :: a -> a @ l
wrap :: forall a (l :: LocTy). a -> a @ l
wrap = forall a (l :: LocTy). a -> a @ l
Wrap
unwrap :: a @ l-> a
unwrap :: forall a (l :: LocTy). (a @ l) -> a
unwrap (Wrap a
a) = a
a
unwrap a @ l
Empty = forall a. HasCallStack => LocTm -> a
error LocTm
"this should never happen for a well-typed choreography"
mkLoc :: String -> Q [Dec]
mkLoc :: LocTm -> Q [Dec]
mkLoc LocTm
loc = do
let locName :: Name
locName = LocTm -> Name
mkName LocTm
loc
let p :: Name
p = LocTm -> Name
mkName LocTm
"Data.Proxy.Proxy"
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Name -> Type -> Dec
SigD Name
locName (Type -> Type -> Type
AppT (Name -> Type
ConT Name
p) (TyLit -> Type
LitT (LocTm -> TyLit
StrTyLit LocTm
loc))),Pat -> Body -> [Dec] -> Dec
ValD (Name -> Pat
VarP Name
locName) (Exp -> Body
NormalB (Name -> Exp
ConE Name
p)) []]