{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE TypeFamilies #-}
module Prosidy.Compile.Core.Interpret
( Context(..)
, Interpret(..)
, interpret
)
where
import Control.Applicative ( Alternative )
import Prosidy.Compile.Core.Rules ( RuleFor
, Rules
, Rule(..)
, runRules
)
import Data.Void.HKT ( Void
, absurd
)
class (forall i. Alternative (t i)) => Context t where
runSelf :: t i i
type Local t :: * -> *
liftRule :: Local t a -> t i a
type Local t = Void t
default liftRule :: Local t a ~ Void t a => Local t a -> t i a
liftRule = Local t a -> t i a
forall a b. Uninhabited a => a -> b
absurd
class Context t => Interpret t i where
runRule :: RuleFor i (Local t) a -> t i a
default runRule :: (RuleFor i ~ Void i) => RuleFor i (Local t) a -> t i a
runRule = RuleFor i (Local t) a -> t i a
forall a b. Uninhabited a => a -> b
absurd
interpret :: forall t i a. Interpret t i => Rules i (Local t) a -> t i a
interpret :: Rules i (Local t) a -> t i a
interpret = (forall b. Rule i (Local t) b -> t i b)
-> Rules i (Local t) a -> t i a
forall (g :: * -> *) t (f :: * -> *) a.
Alternative g =>
(forall b. Rule t f b -> g b) -> Rules t f a -> g a
runRules ((forall b. Rule i (Local t) b -> t i b)
-> Rules i (Local t) a -> t i a)
-> (forall b. Rule i (Local t) b -> t i b)
-> Rules i (Local t) a
-> t i a
forall a b. (a -> b) -> a -> b
$ \x :: Rule i (Local t) b
x -> case Rule i (Local t) b
x of
RuleFor r :: RuleFor i (Local t) b
r -> RuleFor i (Local t) b -> t i b
forall (t :: * -> * -> *) i a.
Interpret t i =>
RuleFor i (Local t) a -> t i a
runRule RuleFor i (Local t) b
r
Escape f :: Local t b
f -> Local t b -> t i b
forall (t :: * -> * -> *) a i. Context t => Local t a -> t i a
liftRule Local t b
f
Self s :: i -> b
s -> i -> b
s (i -> b) -> t i i -> t i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t i i
forall (t :: * -> * -> *) i. Context t => t i i
runSelf