about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--yants-tests.nix6
-rw-r--r--yants.nix15
-rw-r--r--z-functions.pngbin0 -> 32907 bytes
3 files changed, 20 insertions, 1 deletions
diff --git a/yants-tests.nix b/yants-tests.nix
index 8847758ced8a..e089aab4670a 100644
--- a/yants-tests.nix
+++ b/yants-tests.nix
@@ -45,4 +45,10 @@ deepSeq rec {
     blue = throw "It should not be blue!";
     green = throw "It should not be green!";
   };
+
+  # Test curried function definitions
+  func = defun [ string int string ]
+  (name: age: "${name} is ${toString age} years old");
+
+  testFunc = func "Brynhjulf" 42;
 } "All tests passed!\n"
diff --git a/yants.nix b/yants.nix
index a24792f8a5e4..51bc5fe5c433 100644
--- a/yants.nix
+++ b/yants.nix
@@ -74,6 +74,19 @@ with builtins; let
        else actions."${__functor { inherit name check; } x}";
   };
 
+  mkFunc = sig: f: {
+    inherit sig;
+    __toString = self: foldl' (s: t: "${s} -> ${t.name}")
+                              "λ :: ${(head self.sig).name}" (tail self.sig);
+    __functor = _: f;
+  };
+  defun' = sig: func: if length sig > 2
+    then mkFunc sig (x: defun' (tail sig) (func ((head sig) x)))
+    else mkFunc sig (x: ((head (tail sig)) (func ((head sig) x))));
+
+  defun = sig: func: if length sig < 2
+    then (throw "Signature must at least have two types (a -> b)")
+    else defun' sig func;
 in (typeSet [
   # Primitive types
   (typedef "any" (_: true))
@@ -98,4 +111,4 @@ in (typeSet [
   )) true (attrValues v))))
 
   (poly2 "either" (t1: t2: v: t1.check v || t2.check v))
-]) // { inherit struct enum; }
+]) // { inherit struct enum defun; }
diff --git a/z-functions.png b/z-functions.png
new file mode 100644
index 000000000000..30ed50f8327b
--- /dev/null
+++ b/z-functions.png
Binary files differ