@@ -1,11 +1,10 @@
11{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
22
33module Core.Evaluate(normalise,
4− Fun(..), Def(..), Context, toAlist,
5− emptyContext, addToCtxt, addConstant, addDatatype,
4+ Fun(..), Def(..), Context,
5+ addToCtxt, addConstant, addDatatype,
66 lookupTy, lookupP, lookupDef, lookupVal, lookupTyEnv) where
77
8−import qualified Data.Map as Map
98import Debug.Trace
109import Core.TT
1110
@@ -94,36 +93,25 @@ wknV i t = t
9493data Fun = Fun Type Value Term Value
9594 deriving Show
9695
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. -}
101+
97102data Def = Function Fun
98103 | Constant NameType Type Value
99− deriving Show
100−
101−{-
102−type Context = [(Name, Def)]
103−
104−emptyContext = []
105−
106−addDef :: Name -> Def -> Context -> Context
107−addDef n d ctxt = (n, d) : ctxt
108−
109−lookupCtxt :: Name -> Context -> Maybe Def
110−lookupCtxt n c = lookup n c
111−-}
104+ | Operator Type [(Term, Term)] ([Value] -> Maybe Value)
112105
113−type Context = Map.Map Name Def
114−emptyContext = Map.empty
115−
116−addDef :: Name -> Def -> Context -> Context
117−addDef = Map.insert
118−
119−lookupCtxt :: Name -> Context -> Maybe Def
120−lookupCtxt = Map.lookup
121−
122−toAlist :: Context -> [(Name, Def)]
123−toAlist = Map.toList
106+instance Show Def where
107+ show (Function f) = "Function: " ++ show f
108+ show (Constant nt ty val) = "Constant: " ++ show nt ++ " " ++ show ty
109+ show (Operator ty ps _) = "Operator: " ++ show ty ++ " " ++ show ps
124110
125111-------
126112
113+type Context = Ctxt Def
114+
127115addToCtxt :: Name -> Term -> Type -> Context -> Context
128116addToCtxt n tm ty ctxt = addDef n (Function (Fun ty (eval ctxt [] ty)
129117 tm (eval ctxt [] tm))) ctxt