diff --git a/core/Generics.carp b/core/Generics.carp index 456050e3..b1598291 100644 --- a/core/Generics.carp +++ b/core/Generics.carp @@ -74,6 +74,7 @@ The margin of error is 0.00001.") (not (neg? x))) (defn id [x] x) +(defn const [x] (fn [_] x)) (defn null? [p] (Pointer.eq NULL (the (Ptr t) p))) @@ -106,4 +107,4 @@ The margin of error is 0.00001.") (defn /= [a b] (not (= a b))) -) \ No newline at end of file +) diff --git a/test/generics.carp b/test/generics.carp new file mode 100644 index 00000000..082477e2 --- /dev/null +++ b/test/generics.carp @@ -0,0 +1,21 @@ +(load "Test.carp") + +(use Test) + +(deftest test + (assert-equal test + 1 + (id 1) + "id works I" + ) + (assert-equal test + &(Maybe.Just 1) + &(id (Maybe.Just 1)) + "id works II" + ) + (assert-equal test + 20 + ((const 20) 1) + "const works" + ) +)