| Copyright | (c) Nadia Yvette Chambers 2026 |
|---|---|
| License | EUPL-1.2 |
| Maintainer | Nadia Chambers <nadia.yvette.chambers@ik.me> |
| Stability | experimental |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Cek.Dhall
Description
Implements a tailored Felleisen-Friedman CEK machine for the normalization and evaluation of Dhall language constructs (natural numbers, integers, booleans, text, records, projections, lists, and closures).
Architectural Context
Per Note [Felleisen-Friedman CEK Abstract Machine] [ref:note-core-architecture],
this module models Dhall strong normalization through tail-recursive transition steps:
* Record fields are evaluated inside-out.
* Projections (DField) resolve against fully evaluated record values.
* Operators (DOpPlus, DOpTextAppend) evaluate operands strictly before combining.
Synopsis
- data DhallExpr
- data DhallVal
- newtype DhallEnv = DhallEnv {
- unDhallEnv :: [(Text, DhallVal)]
- emptyDhallEnv :: DhallEnv
- extendDhallEnv :: Text -> DhallVal -> DhallEnv -> DhallEnv
- lookupDhallEnv :: Text -> DhallEnv -> Maybe DhallVal
- data DhallFrame
- = DFrameArg !DhallExpr !DhallEnv
- | DFrameFun !DhallVal
- | DFrameLet !Text !DhallExpr !DhallEnv
- | DFrameField !Text
- | DFrameOpPlusR !DhallExpr !DhallEnv
- | DFrameOpPlusL !Word64
- | DFrameOpTextR !DhallExpr !DhallEnv
- | DFrameOpTextL !Text
- type DhallCont = [DhallFrame]
- emptyDhallCont :: DhallCont
- data DhallState
- stepDhallCEK :: DhallState -> Either Text (Maybe DhallState)
- evalDhallCEK :: DhallExpr -> Either Text DhallVal
Dhall AST
Abstract syntax for normalized Dhall expressions.
Constructors
| DVar !Text | Variable identifier |
| DLam !Text !DhallExpr | Lambda abstraction (\(\lambda x. e\)) |
| DApp !DhallExpr !DhallExpr | Function application |
| DLet !Text !DhallExpr !DhallExpr | Let-binding ( |
| DNat !Word64 | Natural literal ( |
| DInt !Integer | Signed integer literal ( |
| DBool !Bool | Boolean literal ( |
| DText !Text | Text literal ( |
| DRecord ![(Text, DhallExpr)] | Record literal ( |
| DField !DhallExpr !Text | Field selection ( |
| DList ![DhallExpr] | List literal ( |
| DOpPlus !DhallExpr !DhallExpr | Natural addition ( |
| DOpTextAppend !DhallExpr !DhallExpr | Text concatenation ( |
Instances
| Eq DhallExpr Source # | |||||
| Generic DhallExpr Source # | |||||
Defined in Cek.Dhall Associated Types
| |||||
| Show DhallExpr Source # | |||||
| type Rep DhallExpr Source # | |||||
Defined in Cek.Dhall type Rep DhallExpr = D1 ('MetaData "DhallExpr" "Cek.Dhall" "cek-dhall-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "DVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: (C1 ('MetaCons "DLam" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr)) :+: C1 ('MetaCons "DApp" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr)))) :+: (C1 ('MetaCons "DLet" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr))) :+: (C1 ('MetaCons "DNat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "DInt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer))))) :+: ((C1 ('MetaCons "DBool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)) :+: (C1 ('MetaCons "DText" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "DRecord" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Text, DhallExpr)])))) :+: ((C1 ('MetaCons "DField" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "DList" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [DhallExpr]))) :+: (C1 ('MetaCons "DOpPlus" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr)) :+: C1 ('MetaCons "DOpTextAppend" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr)))))) | |||||
Value Domain
Normalized Dhall values.
Constructors
| VNat !Word64 | Natural number value |
| VInt !Integer | Integer value |
| VBool !Bool | Boolean value |
| VText !Text | Text string value |
| VClosure !Text !DhallExpr !DhallEnv | Lexical closure \(\langle x, e, E \rangle\) |
| VRecord ![(Text, DhallVal)] | Fully evaluated record value |
| VList ![DhallVal] | Evaluated list value |
Instances
| Eq DhallVal Source # | |||||
| Generic DhallVal Source # | |||||
Defined in Cek.Dhall Associated Types
| |||||
| Show DhallVal Source # | |||||
| type Rep DhallVal Source # | |||||
Defined in Cek.Dhall type Rep DhallVal = D1 ('MetaData "DhallVal" "Cek.Dhall" "cek-dhall-0.1.0.0-inplace" 'False) ((C1 ('MetaCons "VNat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: (C1 ('MetaCons "VInt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "VBool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))) :+: ((C1 ('MetaCons "VText" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "VClosure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv)))) :+: (C1 ('MetaCons "VRecord" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Text, DhallVal)])) :+: C1 ('MetaCons "VList" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [DhallVal]))))) | |||||
Lexical environment for Dhall evaluation.
Constructors
| DhallEnv | |
Fields
| |
emptyDhallEnv :: DhallEnv Source #
Construct an empty Dhall environment.
extendDhallEnv :: Text -> DhallVal -> DhallEnv -> DhallEnv Source #
Extend a Dhall environment with a variable binding.
lookupDhallEnv :: Text -> DhallEnv -> Maybe DhallVal Source #
Lookup a variable in a Dhall environment.
Continuation Frames
data DhallFrame Source #
Continuation frames for Dhall evaluation contexts.
Constructors
| DFrameArg !DhallExpr !DhallEnv | Waiting for function argument |
| DFrameFun !DhallVal | Waiting for function body to apply |
| DFrameLet !Text !DhallExpr !DhallEnv | Waiting for let-bound definition |
| DFrameField !Text | Waiting for record expression to project field |
| DFrameOpPlusR !DhallExpr !DhallEnv | Waiting for right operand of addition |
| DFrameOpPlusL !Word64 | Waiting to add left natural |
| DFrameOpTextR !DhallExpr !DhallEnv | Waiting for right operand of text append |
| DFrameOpTextL !Text | Waiting to append left text |
Instances
| Eq DhallFrame Source # | |||||
Defined in Cek.Dhall | |||||
| Generic DhallFrame Source # | |||||
Defined in Cek.Dhall Associated Types
| |||||
| Show DhallFrame Source # | |||||
Defined in Cek.Dhall Methods showsPrec :: Int -> DhallFrame -> ShowS show :: DhallFrame -> String showList :: [DhallFrame] -> ShowS | |||||
| type Rep DhallFrame Source # | |||||
Defined in Cek.Dhall type Rep DhallFrame = D1 ('MetaData "DhallFrame" "Cek.Dhall" "cek-dhall-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "DFrameArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv)) :+: C1 ('MetaCons "DFrameFun" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallVal))) :+: (C1 ('MetaCons "DFrameLet" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv))) :+: C1 ('MetaCons "DFrameField" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))) :+: ((C1 ('MetaCons "DFrameOpPlusR" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv)) :+: C1 ('MetaCons "DFrameOpPlusL" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64))) :+: (C1 ('MetaCons "DFrameOpTextR" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv)) :+: C1 ('MetaCons "DFrameOpTextL" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text))))) | |||||
type DhallCont = [DhallFrame] Source #
Dhall continuation stack.
emptyDhallCont :: DhallCont Source #
Construct an empty Dhall continuation stack.
Machine State & Evaluator
data DhallState Source #
Active state of the Dhall CEK abstract machine.
Constructors
| DStateEval !DhallExpr !DhallEnv !DhallCont | Control expression \(C\), environment \(E\), continuation \(K\) |
| DStateReturn !DhallVal !DhallCont | Value \(V\) being delivered to continuation \(K\) |
Instances
| Eq DhallState Source # | |||||
Defined in Cek.Dhall | |||||
| Generic DhallState Source # | |||||
Defined in Cek.Dhall Associated Types
| |||||
| Show DhallState Source # | |||||
Defined in Cek.Dhall Methods showsPrec :: Int -> DhallState -> ShowS show :: DhallState -> String showList :: [DhallState] -> ShowS | |||||
| type Rep DhallState Source # | |||||
Defined in Cek.Dhall type Rep DhallState = D1 ('MetaData "DhallState" "Cek.Dhall" "cek-dhall-0.1.0.0-inplace" 'False) (C1 ('MetaCons "DStateEval" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallExpr) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallEnv) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallCont))) :+: C1 ('MetaCons "DStateReturn" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallVal) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DhallCont))) | |||||
stepDhallCEK :: DhallState -> Either Text (Maybe DhallState) Source #
Advance the Dhall CEK machine by a single deterministic transition step.
evalDhallCEK :: DhallExpr -> Either Text DhallVal Source #
Evaluate a Dhall expression to its final normalized value under the empty environment.