Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Created May 4, 2015 23:45
Show Gist options
  • Save frenchy64/87fd797b00a9c6493e79 to your computer and use it in GitHub Desktop.
Save frenchy64/87fd797b00a9c6493e79 to your computer and use it in GitHub Desktop.

Polymorphic contracts

(ns utyped1)

(defn id identity)
(ns ^:core.typed typed
  (:require [clojure.core.typed :as t]
            [^{:require-typed
               {id (t/All [x] [x -> x])}}
             utyped1 :as u]))

(t/ann fidentity
  (All [[x :< [Int -> Int]]] [x -> x]))
(def fidentity identity)
;  (fn [X]
;    (fn [a :- X]
;      ((inst identity X) a))))

(deftype [X] Cons [fst rst]
  PCons
  (first [this] ((inst u/id X) fst))
(ns untyped
  (:require [typed :as tt]))

;; t/fidentity considered [[Int -> Int] -> Any]
(t/fidentity (cast (fn [a] a) [Int -> Int]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment