Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Created December 5, 2012 08:05
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/4213669 to your computer and use it in GitHub Desktop.
Save frenchy64/4213669 to your computer and use it in GitHub Desktop.
(ns typed.test.person
(:require [typed.core
:refer [check-ns cf ann-datatype ann
tc-ignore ann-protocol AnyInteger]]))
(ann-protocol Age
:methods
{age [Age -> AnyInteger]})
(tc-ignore
(defprotocol Age
(age [this]))
)
(ann-datatype Person
[(name :- String)
(age :- AnyInteger)])
(deftype Person [name age]
Age
(age [this] age))
(age (Person. "Lucy" 34))
(ann my-apply (All [x y] [[x -> y] x -> y]))
(defn my-apply [f a]
(f a))
(my-apply age nil)
;; REPL
; error messages for polymorphic function applications now have:
; - line number (and column if using Clojure 1.5.0-beta1)
; - expected domain types
; - actual argument types
; - macroexpanded original form
typed.test.person=> (check-ns)
#<Exception java.lang.Exception: 28: Polymorphic function typed.test.person/my-apply could not be applied to arguments:
Domains:
(Fn [x -> y]) x
Args:
(Fn [typed.test.person/Age -> (U java.lang.Integer java.math.BigInteger java.lang.Byte java.lang.Short clojure.lang.BigInt java.lang.Long)]) nil
in: (typed.test.person/my-apply typed.test.person/age nil)>
typed.test.person=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment