add naive Terminal type
This commit is contained in:
parent
3c8ccea4a1
commit
35737d1618
2 changed files with 39 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ in
|
||||||
parse = ./parse/bootstrap.nix;
|
parse = ./parse/bootstrap.nix;
|
||||||
|
|
||||||
maybe = ./maybe.nix;
|
maybe = ./maybe.nix;
|
||||||
|
terminal = ./terminal.nix;
|
||||||
trapdoor = ./trapdoor.nix;
|
trapdoor = ./trapdoor.nix;
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
38
nt/primitives/bootstrap/terminal.nix
Normal file
38
nt/primitives/bootstrap/terminal.nix
Normal 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_;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue