| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cek.OneML
Description
Models 1ML structures and signatures as flat SchemaId-indexed arrays of lazy
SoAStore addresses, using MergeMorph3 for module include (OpPreferR)
and existential sealing Mod :> Sig (OpRestrict).
Background: Rossberg's 1ML
Andreas Rossberg's "1ML — Core and the Modules in the Same Language" (ICFP 2015) showed that the traditional stratified distinction between ML core expressions and ML modules (structures, signatures, functors) can be completely dissolved. Modules become first-class records, functors become ordinary functions, and signatures become first-class record types with existential components.
Efficient Interpretation with MergeMorph3
Traditional implementations of 1ML require heavy elaborators that translate module constructs into System \(F_\omega\) terms with dynamic dictionary passing. This CEK machine implementation executes 1ML directly on flat unboxed structures:
- Structures and signatures are flat arrays of lazy cells indexed by
FieldIdand mapped to structuralSchemaIdidentifiers inHiddenClass. - Module extension (
include M) compiles into a single $O(N_1 + N_2)$ linear merge plan (OpPreferR) viasynthesizeMergeMorph3. - Existential sealing (
Mod :> Sig) computes a domain restriction (OpRestrict) in $O(|Sig|)$ time. For every abstract type field (SpecAbstract), the evaluator mints a fresh, globally unique skolem constant (CT_WNeu) inSoAStore, hiding the concrete implementation without dynamic wrapper closures.
**Demonstrative Reference Implementation**: This package is an educational and demonstrative reference implementation showcasing Andreas Rossberg's 1ML first-class module system over the CEK abstract machine with MergeMorph3 existential sealing and Pykinos hidden classes. It is provided primarily as an executable architectural example within the @cek@ ecosystem documentation.
Synopsis
- data TypeSpec
- data OneMLTerm
- data OneMLWHNF
- = V1Lit !Int32
- | V1Spec !TypeSpec ![Int32]
- | V1Functor !Int32 !OneMLTerm ![Int32]
- | V1Struct !SchemaId !(SmallArray Int32)
- | V1AbstractType !Int32
- pattern FT_1ML_App :: FrameTag
- pattern FT_1ML_Proj :: FrameTag
- pattern FT_1ML_IncludeL :: FrameTag
- pattern FT_1ML_IncludeR :: FrameTag
- pattern FT_1ML_SealSig :: FrameTag
- pattern FT_1ML_SealMod :: FrameTag
- stepOneMLSealing :: SoAStore s -> MutableByteArray s -> MergeMorph3 -> SchemaId -> SmallArray Int32 -> SmallArray Int32 -> ST s OneMLWHNF
- evalOneML :: (SchemaId -> PrimArray Word32) -> (PrimArray Word32 -> SchemaId) -> OneMLTerm -> OneMLWHNF
Type Specifications
Type specifications inside a 1ML signature structure.
Constructors
| SpecAbstract | Opaque abstract type field ( |
| SpecManifest !OneMLTerm | Transparent type alias ( |
| SpecVal !OneMLTerm | Value field specification ( |
1ML Syntax
Unified 1ML Core and Module AST.
Constructors
| MVar !Int | Variable reference resolved via De Bruijn indexing into the environment. |
| MLit !Int32 | 32-bit signed integer literal value. |
| MReified !TypeSpec | Reified first-class type specification treated as a value. |
| MFunctor !OneMLTerm !OneMLTerm | First-class functor / function abstraction taking a domain signature and body. |
| MApp !OneMLTerm !OneMLTerm | Application of a functor to a module argument. |
| MLet !OneMLTerm !OneMLTerm | Lexical let binding introducing a local module or value definition. |
| MStruct !SchemaId !(SmallArray OneMLTerm) | First-class module structure pairing an interned |
| MProj !OneMLTerm !FieldId | Structure projection |
| MInclude !OneMLTerm !OneMLTerm | Asymmetric module inclusion / union |
| MSeal !OneMLTerm !OneMLTerm | Existential signature sealing |
Values and Weak-Head Normal Forms
Weak-Head Normal Form representation for 1ML values and modules.
Constructors
| V1Lit !Int32 | Unboxed integer literal value. |
| V1Spec !TypeSpec ![Int32] | Evaluated type specification closure. |
| V1Functor !Int32 !OneMLTerm ![Int32] | Evaluated functor closure capturing parameter domain address, body, and env. |
| V1Struct !SchemaId !(SmallArray Int32) | Evaluated structure pairing a |
| V1AbstractType !Int32 | Opaque existential skolem type constant generated during signature sealing. |
Continuation Frame Tags
pattern FT_1ML_App :: FrameTag Source #
Frame tag for evaluating a functor argument cell.
pattern FT_1ML_Proj :: FrameTag Source #
Frame tag for projecting a field from an evaluated module structure.
pattern FT_1ML_IncludeL :: FrameTag Source #
Frame tag for evaluating the left-hand module in an include (//) expression.
pattern FT_1ML_IncludeR :: FrameTag Source #
Frame tag for evaluating the right-hand module in an include (//) expression.
pattern FT_1ML_SealSig :: FrameTag Source #
Frame tag for evaluating the signature expression in existential sealing.
pattern FT_1ML_SealMod :: FrameTag Source #
Frame tag for applying signature restriction and skolemization to the module structure.
Sealing and Evaluation
stepOneMLSealing :: SoAStore s -> MutableByteArray s -> MergeMorph3 -> SchemaId -> SmallArray Int32 -> SmallArray Int32 -> ST s OneMLWHNF Source #
Execute 1ML existential sealing (Mod :> Sig) in O(|Sig|) using MergeMorph3
with OpRestrict. Private fields omitted from Sig are never forced, while
SpecAbstract fields mint fresh skolem symbols in SoAStore.