Created
December 5, 2012 08:05
-
-
Save frenchy64/4213669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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