{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | Expression for 'MonoFunctor'. module Language.Symantic.Expr.MonoFunctor where import Control.Monad (liftM2) import Data.Proxy (Proxy(..)) import Data.Type.Equality ((:~:)(Refl)) import Prelude hiding (fmap) -- import qualified Data.Function as Fun import qualified Data.MonoTraversable as MT import Data.MonoTraversable (MonoFunctor) import Language.Symantic.Type import Language.Symantic.Repr import Language.Symantic.Expr.Root import Language.Symantic.Expr.Error import Language.Symantic.Expr.From import Language.Symantic.Expr.Lambda import Language.Symantic.Trans.Common -- * Class 'Sym_MonoFunctor' -- | Symantic. class Sym_Lambda repr => Sym_MonoFunctor repr where omap :: MonoFunctor m => repr (MT.Element m -> MT.Element m) -> repr m -> repr m default omap :: (Trans t repr, MonoFunctor m) => t repr (MT.Element m -> MT.Element m) -> t repr m -> t repr m omap = trans_map2 omap instance Sym_MonoFunctor Repr_Host where omap = liftM2 MT.omap instance Sym_MonoFunctor Repr_Text where omap = repr_text_app2 "omap" instance ( Sym_MonoFunctor r1 , Sym_MonoFunctor r2 ) => Sym_MonoFunctor (Repr_Dup r1 r2) where omap (f1 `Repr_Dup` f2) (m1 `Repr_Dup` m2) = omap f1 m1 `Repr_Dup` omap f2 m2 -- * Type 'Expr_MonoFunctor' -- | Expression. data Expr_MonoFunctor (root:: *) type instance Root_of_Expr (Expr_MonoFunctor root) = root type instance Type_of_Expr (Expr_MonoFunctor root) = No_Type type instance Sym_of_Expr (Expr_MonoFunctor root) repr = (Sym_MonoFunctor repr) type instance Error_of_Expr ast (Expr_MonoFunctor root) = No_Error_Expr -- | Parse 'omap'. omap_from :: forall root ty ast hs ret. ( ty ~ Type_Root_of_Expr (Expr_MonoFunctor root) , Type0_Eq ty , Expr_From ast root , Type0_Lift Type_Fun (Type_of_Expr root) , Type0_Unlift Type_Fun (Type_of_Expr root) , Error_Expr_Lift (Error_Expr (Error_of_Type ast ty) ty ast) (Error_of_Expr ast root) , Root_of_Expr root ~ root , Type0_Constraint MonoFunctor ty , Type0_Family Type_Family_MonoElement ty ) => ast -> ast -> ExprFrom ast (Expr_MonoFunctor root) hs ret omap_from ast_f ast_m ex ast ctx k = -- NOTE: omap :: (Element mono -> Element mono) -> mono -> mono expr_from (Proxy::Proxy root) ast_f ctx $ \(ty_f::ty h_f) (Forall_Repr_with_Context f) -> expr_from (Proxy::Proxy root) ast_m ctx $ \(ty_m::ty h_m) (Forall_Repr_with_Context m) -> check_type_fun ex ast ty_f $ \(Type2 Proxy ty_f_a ty_f_b) -> check_type0_constraint ex (Proxy::Proxy MonoFunctor) ast ty_m $ \Dict -> check_type0_eq ex ast ty_f_a ty_f_b $ \Refl -> check_type0_family (Proxy::Proxy Type_Family_MonoElement) ex ast ty_m $ \ty_m_ele -> check_type0_eq ex ast ty_f_a ty_m_ele $ \Refl -> k ty_m $ Forall_Repr_with_Context $ \c -> omap (f c) (m c)