Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created July 15, 2011 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swannodette/1083967 to your computer and use it in GitHub Desktop.
Save swannodette/1083967 to your computer and use it in GitHub Desktop.
typed.clj
(defne geto [k m v]
([_ [[k :- v] . _] _])
([_ [_ . ?r] _] (geto k ?r v)))
(defn typedo [c x t]
(conde
((geto x c t))
((matche [c x t]
([_ [:apply ?a ?b] _]
(exist [s nc]
(!= ?a ?b)
(typedo c ?a [s :> t])
(typedo c ?b s)))))))
(comment
;; ([_.0 :> _.1])
(run* [q]
(exist [a t]
(typedo [[:f :- q] [:g :- a]] [:apply :f :g] t)))
;; (:int)
(run* [q]
(typedo [[:g :- :int]] :g q))
;; ([:int :> _.0])
(run* [q]
(exist [t]
(typedo [[:f :- q] [:g :- :int]] [:apply :f :g] t)))
; (:int)
(run* [q]
(exist [t]
(typedo [[:f :- [:int :> :float]] [:g :- q]]
[:apply :f :g] t)))
;; ()
(run* [q]
(exist [t]
(typedo [[:f :- q]] [:apply :f :f] t)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment