TermEnv.hs 1 KB
Newer Older
Sven Keidel's avatar
Sven Keidel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE Arrows #-}
module Data.TermEnv where

import           Syntax (TermVar)

import           Control.Category
import           Control.Arrow

class Arrow c => IsTermEnv env t c | c -> env, env -> t where
  getTermEnv :: c () env
  putTermEnv :: c env ()
  lookupTermVar :: c t t -> c () t -> c (TermVar,env) t
  insertTerm :: c (TermVar,t,env) env
  deleteTermVars :: c ([TermVar],env) env
  unionTermEnvs :: c ([TermVar],env,env) env

lookupTermVar' :: IsTermEnv env t c => c t t -> c () t -> c TermVar t
lookupTermVar' f g = proc v -> do
  env <- getTermEnv -< ()
  lookupTermVar f g -< (v,env)

insertTerm' :: IsTermEnv env t c => c (TermVar,t) ()
insertTerm' = proc (v,t) -> do
  env <- getTermEnv -< ()
  putTermEnv <<< insertTerm -< (v,t,env)

deleteTermVars' :: IsTermEnv env t c => c [TermVar] ()
deleteTermVars' = proc vs -> do
  env <- getTermEnv -< ()
  putTermEnv <<< deleteTermVars -< (vs,env)