Skip to content

Instantly share code, notes, and snippets.

@frenchy64 frenchy64/colored.clj
Last active Aug 28, 2018

What would you like to do?
(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
You can’t perform that action at this time.