-
-
Save jcromartie/f2e6713ba14261115dde to your computer and use it in GitHub Desktop.
Crude type checking?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn | |
^{:types [Integer Integer Integer]} | |
add | |
[x y] | |
(+ x y)) | |
(defn | |
^{:types [Integer Integer Integer]} | |
mult | |
[x y] | |
(* x y)) | |
(defn typecheck* | |
[code] | |
(let [types (-> code first meta :types) | |
f-type (first types) | |
expected-arg-types (rest types) | |
actual-arg-types (map type (rest code))] | |
(when (some false? (map #(isa? %1 %2) actual-arg-types expected-arg-types)) | |
(throw (Exception. "Type error"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment