move nt specifics from trapdoor.nix/sig.nix -> nt.nix
This commit is contained in:
parent
9804d2e95a
commit
25d00f7a2f
2 changed files with 28 additions and 4 deletions
|
|
@ -5,14 +5,14 @@
|
|||
attrNames
|
||||
elem
|
||||
isAttrs
|
||||
isString
|
||||
typeOf
|
||||
;
|
||||
|
||||
inherit
|
||||
(this)
|
||||
enfIsNT
|
||||
ntTrapdoorKey
|
||||
mkTrapdoorKey
|
||||
openTrapdoor
|
||||
toTypeSig
|
||||
;
|
||||
in rec {
|
||||
# check if a value is an nt type/class
|
||||
|
|
@ -56,4 +56,29 @@ in rec {
|
|||
|
||||
# NOTE safe variant, use `is'` if you can guarantee `isNT T` holds
|
||||
is = type: T: assert enfIsNT T "nt.is"; is' type T;
|
||||
|
||||
# NOTE: unsafe variant, use typeSig if you can't guarantee `isNT T` holds
|
||||
typeSig' = T: T.${ntTrapdoorKey}.sig;
|
||||
|
||||
# # NOTE: safe variant, use typeSig' if you can guarantee `isNT T` holds
|
||||
typeSig = T: assert enfIsNT T "nt.typeSig"; typeSig' T;
|
||||
|
||||
toTypeSig = x:
|
||||
if isString x
|
||||
then x
|
||||
else typeSig x;
|
||||
|
||||
# XXX: TODO: move ntTrapdoorKey to nt.nix
|
||||
ntTrapdoorKey = mkTrapdoorKey "nt";
|
||||
|
||||
enfIsType = type: value: msg: let
|
||||
got = typeOf value;
|
||||
in
|
||||
got == type || throw "${msg}: expected primitive nix type \"${type}\" but got \"${got}\"";
|
||||
|
||||
enfIsNT = T: msg:
|
||||
isNT T || throw "${msg}: expected nt compatible type but got \"${toString T}\" of primitive nix type \"${typeOf T}\"";
|
||||
|
||||
enfImpls = type: T: msg:
|
||||
impls type T || throw "${msg}: given type \"${toTypeSig T}\" does not implement typeclass \"${toTypeSig type}\"";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ in rec {
|
|||
masterkey = "_''traps''_";
|
||||
defaultTrapdoorKey = "_'";
|
||||
mkTrapdoorKey = id: "${defaultTrapdoorKey}${id}";
|
||||
ntTrapdoorKey = mkTrapdoorKey "nt";
|
||||
|
||||
mkTrapdoorFn = key: decl:
|
||||
assert enfHasAttr "default" decl "mkTrapdoorFn";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue