{-# OPTIONS_HADDOCK show-extensions #-}
{-# LANGUAGE TemplateHaskell #-}
module Unbound.Generics.LocallyNameless.TH (makeClosedAlpha) where
import Language.Haskell.TH
import Control.Applicative (Applicative(..))
import Data.Monoid (Monoid(..))
import Unbound.Generics.LocallyNameless.Alpha (Alpha(..))
makeClosedAlpha :: Name -> DecsQ
makeClosedAlpha :: Name -> DecsQ
makeClosedAlpha Name
tyName = do
let valueD :: Name -> m Exp -> m Dec
valueD Name
vName m Exp
e = m Pat -> m Body -> [m Dec] -> m Dec
forall (m :: * -> *).
Quote m =>
m Pat -> m Body -> [m Dec] -> m Dec
valD (Name -> m Pat
forall (m :: * -> *). Quote m => Name -> m Pat
varP Name
vName) (m Exp -> m Body
forall (m :: * -> *). Quote m => m Exp -> m Body
normalB m Exp
e) []
methods :: [Q Dec]
methods =
[
Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"aeq'") [e| \_ctx -> (==) |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"fvAny'") [e| \_ctx _nfn -> pure |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'close [e| \_ctx _b -> id |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'open [e| \_ctx _b -> id |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'isPat [e| \_ -> mempty |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'isTerm [e| \_ -> mempty |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'nthPatFind [e| \_ -> mempty |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD 'namePatFind [e| \_ -> mempty |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"swaps'") [e| \_ctx _p -> id |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"freshen'") [e| \_ctx i -> return (i, mempty) |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"lfreshen'") [e| \_ctx i cont -> cont i mempty |]
, Name -> Q Exp -> Q Dec
forall {m :: * -> *}. Quote m => Name -> m Exp -> m Dec
valueD (String -> Name
mkName String
"acompare'") [e| \_ctx -> compare |]
]
Dec
d <- Q Cxt -> Q Type -> [Q Dec] -> Q Dec
forall (m :: * -> *).
Quote m =>
m Cxt -> m Type -> [m Dec] -> m Dec
instanceD ([Q Type] -> Q Cxt
forall (m :: * -> *). Quote m => [m Type] -> m Cxt
cxt []) (Q Type -> Q Type -> Q Type
forall (m :: * -> *). Quote m => m Type -> m Type -> m Type
appT [t|Alpha|] (Name -> Q Type
forall (m :: * -> *). Quote m => Name -> m Type
conT Name
tyName)) [Q Dec]
methods
[Dec] -> DecsQ
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return [Dec
d]