@@ -1,11 +1,10 @@
1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
3module Core.Evaluate(normalise,
3module Core.Evaluate(normalise,
4− Fun(..), Def(..), Context, toAlist,
4+ Fun(..), Def(..), Context,
5− emptyContext, addToCtxt, addConstant, addDatatype,
5+ addToCtxt, addConstant, addDatatype,
6 lookupTy, lookupP, lookupDef, lookupVal, lookupTyEnv) where
6 lookupTy, lookupP, lookupDef, lookupVal, lookupTyEnv) where
8−import qualified Data.Map as Map
9import Debug.Trace
8import Debug.Trace
10import Core.TT
9import Core.TT
@@ -94,36 +93,25 @@ wknV i t = t
94data Fun = Fun Type Value Term Value
93data Fun = Fun Type Value Term Value
95 deriving Show
94 deriving Show
96+{- A definition is either a simple function (just an expression with a type),
97+ a constant, which could be a data or type constructor, an axiom or as an
98+ yet undefined function, or an Operator.
99+ An Operator is a collection of pattern matching definitions, and a function
100+ which explains how to reduce. -}
97data Def = Function Fun
102data Def = Function Fun
98 | Constant NameType Type Value
103 | Constant NameType Type Value
99− deriving Show
104+ | Operator Type [(Term, Term)] ([Value] -> Maybe Value)
102−type Context = [(Name, Def)]
106−addDef :: Name -> Def -> Context -> Context
107−addDef n d ctxt = (n, d) : ctxt
109−lookupCtxt :: Name -> Context -> Maybe Def
110−lookupCtxt n c = lookup n c
113−type Context = Map.Map Name Def
106+instance Show Def where
114−emptyContext = Map.empty
107+ show (Function f) = "Function: " ++ show f
115−
108+ show (Constant nt ty val) = "Constant: " ++ show nt ++ " " ++ show ty
116−addDef :: Name -> Def -> Context -> Context
109+ show (Operator ty ps _) = "Operator: " ++ show ty ++ " " ++ show ps
119−lookupCtxt :: Name -> Context -> Maybe Def
120−lookupCtxt = Map.lookup
122−toAlist :: Context -> [(Name, Def)]
113+type Context = Ctxt Def
127addToCtxt :: Name -> Term -> Type -> Context -> Context
115addToCtxt :: Name -> Term -> Type -> Context -> Context
128addToCtxt n tm ty ctxt = addDef n (Function (Fun ty (eval ctxt [] ty)
116addToCtxt n tm ty ctxt = addDef n (Function (Fun ty (eval ctxt [] ty)
129 tm (eval ctxt [] tm))) ctxt
117 tm (eval ctxt [] tm))) ctxt