completely restruct bootstrap

This commit is contained in:
Emile Clark-Boman 2026-01-28 12:55:12 +10:00
parent 100de72342
commit 0b554315e9
12 changed files with 25 additions and 11 deletions

View file

@ -0,0 +1,38 @@
{...}: let
inherit
(builtins)
attrNames
concatStringsSep
isAttrs
typeOf
;
in rec {
# Naive Terminal Type
# NOTE: preserves lazy eval for _value
Terminal = value: {
_value = value;
};
# Type Checking
isTerminal = T: isAttrs T && attrNames T == ["_value"];
# XXX: TODO: make a pretty toString function
# XXX: TODO: make a pretty toString function
# XXX: TODO: make a pretty toString function
# XXX: TODO: make a pretty toString function
enfIsTerminal = T: msg: let
throw' = got: throw "${msg}: expected naive type Terminal but got ${got}";
attrs =
attrNames T
|> map (name: "\"${name}\"")
|> concatStringsSep ", ";
in
if isAttrs T
then isTerminal T || throw' "attribute set with structure [${attrs}]"
else throw' "value \"${toString T}\" of primitive type \"${typeOf T}\"";
# Unwrap Operation
# Lift a value out of the Terminal context.
unwrapTerminal = T:
assert enfIsTerminal T "unwrapTerminal";
T._value_;
}