{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Language.Haskell.TTH.LetRec (
letrecE,
letrecH,
) where
import Control.Monad.Fix (MonadFix)
import Data.GADT.Compare (GCompare)
import Data.Some (Some (..))
import Language.Haskell.TH.Syntax (Code, Quote, unTypeCode, unsafeCodeCoerce)
import qualified Language.Haskell.TH.LetRec as TH.LetRec
letrecE
:: forall q tag r a. (Ord tag, Quote q, MonadFix q)
=> (forall. tag -> String)
-> (forall m. Monad m => (tag -> m (Code q a)) -> (tag -> m (Code q a)))
-> (forall m. Monad m => (tag -> m (Code q a)) -> m (Code q r))
-> Code q r
letrecE :: forall (q :: * -> *) tag r a.
(Ord tag, Quote q, MonadFix q) =>
(tag -> String)
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> tag -> m (Code q a))
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> m (Code q r))
-> Code q r
letrecE tag -> String
nameOf forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> tag -> m (Code q a)
bindf forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> m (Code q r)
exprf = forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall a b. (a -> b) -> a -> b
$ forall (q :: * -> *) tag.
(Ord tag, Quote q, MonadFix q) =>
(tag -> String)
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (q Exp)) -> tag -> m (q Exp))
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (q Exp)) -> m (q Exp))
-> q Exp
TH.LetRec.letrecE
tag -> String
nameOf
(\tag -> m (q Exp)
recf tag
tag -> forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> tag -> m (Code q a)
bindf (\tag
tag' -> forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> tag -> m (q Exp)
recf tag
tag') tag
tag)
(\tag -> m (q Exp)
recf -> forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
Monad m =>
(tag -> m (Code q a)) -> m (Code q r)
exprf (\tag
tag' -> forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> tag -> m (q Exp)
recf tag
tag'))
letrecH
:: forall q tag r. (GCompare tag, Quote q, MonadFix q)
=> (forall x. tag x -> String)
-> (forall m y. Monad m => (forall x. tag x -> m (Code q x)) -> (tag y -> m (Code q y)))
-> (forall m. Monad m => (forall x. tag x -> m (Code q x)) -> m (Code q r))
-> Code q r
letrecH :: forall (q :: * -> *) (tag :: * -> *) r.
(GCompare tag, Quote q, MonadFix q) =>
(forall x. tag x -> String)
-> (forall (m :: * -> *) y.
Monad m =>
(forall x. tag x -> m (Code q x)) -> tag y -> m (Code q y))
-> (forall (m :: * -> *).
Monad m =>
(forall x. tag x -> m (Code q x)) -> m (Code q r))
-> Code q r
letrecH forall x. tag x -> String
nameOf forall (m :: * -> *) y.
Monad m =>
(forall x. tag x -> m (Code q x)) -> tag y -> m (Code q y)
bindf forall (m :: * -> *).
Monad m =>
(forall x. tag x -> m (Code q x)) -> m (Code q r)
exprf = forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall a b. (a -> b) -> a -> b
$ forall (q :: * -> *) tag.
(Ord tag, Quote q, MonadFix q) =>
(tag -> String)
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (q Exp)) -> tag -> m (q Exp))
-> (forall (m :: * -> *).
Monad m =>
(tag -> m (q Exp)) -> m (q Exp))
-> q Exp
TH.LetRec.letrecE
(\(Some tag a
tag) -> forall x. tag x -> String
nameOf tag a
tag)
(\Some tag -> m (q Exp)
recf (Some tag a
tag) -> forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) y.
Monad m =>
(forall x. tag x -> m (Code q x)) -> tag y -> m (Code q y)
bindf (\tag x
tag' -> forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Some tag -> m (q Exp)
recf (forall {k} (tag :: k -> *) (a :: k). tag a -> Some tag
Some tag x
tag')) tag a
tag)
(\Some tag -> m (q Exp)
recf -> forall a (m :: * -> *). Quote m => Code m a -> m Exp
unTypeCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
Monad m =>
(forall x. tag x -> m (Code q x)) -> m (Code q r)
exprf (\tag x
tag' -> forall a (m :: * -> *). Quote m => m Exp -> Code m a
unsafeCodeCoerce forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Some tag -> m (q Exp)
recf (forall {k} (tag :: k -> *) (a :: k). tag a -> Some tag
Some tag x
tag')))