{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module Language.Expression.GeneralOp where
import Data.Vinyl
import Language.Expression
import Language.Expression.Pretty
data GeneralOp op t a where
Op :: op as r -> Rec t as -> GeneralOp op t r
class EvalOpAt k op where
evalMany :: op as r -> Rec k as -> k r
class PrettyOp op where
prettysPrecOp :: Pretty1 t => Int -> op as a -> Rec t as -> ShowS
instance HFunctor (GeneralOp op) where
instance HTraversable (GeneralOp op) where
htraverse f = \case
Op o args -> Op o <$> rtraverse f args
instance (EvalOpAt k op) => HFoldableAt k (GeneralOp op) where
hfoldMap f = \case
Op o args -> evalMany o (rmap f args)
instance PrettyOp op => Pretty2 (GeneralOp op) where
prettys2Prec p = \case
Op op args -> prettysPrecOp p op args