-
-
Save Lysxia/75e45d89338e44d527224fa78aeec37b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators #-} | |
module D where | |
import Control.Applicative (liftA2) | |
import Data.Kind (Type) | |
data F = VALUE | F :-> F | |
infixr 1 :-> | |
type family Unquote (t :: F) :: Type where | |
Unquote VALUE = Value | |
Unquote (t :-> t') = Unquote t -> Unquote t' | |
data Value | |
data Expr a = Closed (Unquote a) | Open (Expr (VALUE :-> a)) | |
mapExpr :: (Unquote a -> Unquote b) -> Expr a -> Expr b | |
mapExpr f (Closed x) = Closed (f x) | |
mapExpr f (Open y) = Open (mapExpr (fmap f) y) | |
pureExpr :: Unquote a -> Expr a | |
pureExpr = Closed | |
liftA2Expr :: Unquote (a :-> b :-> c) -> Expr a -> Expr b -> Expr c | |
liftA2Expr f (Closed x) y = mapExpr (f x) y | |
liftA2Expr f x (Closed y) = mapExpr (flip f y) x | |
liftA2Expr f (Open x) (Open y) = Open (liftA2Expr (liftA2 f) x y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment