Commit c10cbc33 authored by Nicolas Lenz's avatar Nicolas Lenz

Start work on evaluation algebra

parent 684ae3c4
{-# LANGUAGE OverloadedStrings, LambdaCase #-}
module Katrin.Algebra (KatrinAlg, foldKatrin, katrinAlgTerm) where
import Katrin.Core
import Data.Text (Text)
import qualified Data.Text as T
-- | Algebraic signature (or context-free grammar) for Katrin.
......@@ -54,8 +57,56 @@ foldExp alg (Lambda e1 e2) = lambdaAlg alg (foldExp alg e1) (foldExp alg e2)
-- Useful for compilation into a Katrin term and for testing.
katrinAlgTerm :: KatrinAlg Katrin ValueId ConstrId TypeDef Def TypeExp Exp
katrinAlgTerm = KatrinAlg {
katrinAlg = Katrin, valueIdAlg = ValueId, constrIdAlg = ConstrId,
typeDefAlg = TypeDef, productTypeAlg = ProductType, sumTypeAlg = SumType,
defAlg = Def, literalAlg = Literal, applicationAlg = Application,
variableAlg = Variable, lambdaAlg = Lambda
katrinAlg = Katrin,
valueIdAlg = ValueId,
constrIdAlg = ConstrId,
typeDefAlg = TypeDef,
productTypeAlg = ProductType,
sumTypeAlg = SumType,
defAlg = Def,
literalAlg = Literal,
applicationAlg = Application,
variableAlg = Variable,
lambdaAlg = Lambda
}
-- | Evaluation algebra into a String for Katrin. No type checking is performed.
katrinAlgEval :: KatrinAlg (ValueId -> Maybe Text) ValueId ConstrId [ValueId -> Exp] (ValueId, Text) typeExp ([Def] -> Text)
katrinAlgEval = KatrinAlg {
katrinAlg = \tdefs defs -> \vid -> lookup vid defs,
valueIdAlg = ValueId,
constrIdAlg = ConstrId,
typeDefAlg = \vid te -> undefined,
productTypeAlg = undefined,
sumTypeAlg = undefined,
defAlg = \vid et e -> (vid, undefined),
literalAlg = \cid -> \defs -> T.pack $ show cid,
applicationAlg = \e1 e2 -> \defs -> undefined, -- T.concat [T.pack $ undefined, "(", T.pack $ show undefined, ")"],
variableAlg = \vid -> \case
[] -> T.pack $ show vid
(Def vid te e):defs -> undefined,
lambdaAlg = undefined
}
{-
Template for Katrin algebras
katrinAlgEval = KatrinAlg {
katrinAlg = undefined,
valueIdAlg = undefined,
constrIdAlg = undefined,
typeDefAlg = undefined,
productTypeAlg = undefined,
sumTypeAlg = undefined,
defAlg = undefined,
literalAlg = undefined,
applicationAlg = undefined,
variableAlg = undefined,
lambdaAlg = undefined
}
-}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment