Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Last active August 28, 2018 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frenchy64/c1ee13698ee27f84c3aea4f2b1e8bfe7 to your computer and use it in GitHub Desktop.
Save frenchy64/c1ee13698ee27f84c3aea4f2b1e8bfe7 to your computer and use it in GitHub Desktop.
(ns colored-lti-clj.core)
(defalias List
(TFn [a]
'{:match (All [b] [(ListVisitor a b) :-> b])}))
(defalias ListVisitor
(TFn [a b]
'{:caseNil (All [:-> b])
:caseCons (All [a (List a) :-> b])}))
(ann Nil (All [a] [:-> (List a)]))
(defn Nil []
{:match (fn [v] ((:caseNil v)))})
(ann Cons (All [a] [a (List a) :-> (List a)]))
(defn Cons [x xs]
{:match (fn [v] ((:caseCons v) x xs))})
(ann append (All [c] [(List c) (List c) :-> (List c)]))
(defn append [xs ys]
((:match xs)
{:caseNil (fn [] ys)
:caseCons (fn [x xs1]
(Cons x (append xs1 ys)))}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment