When I work in Scala, I like that I can pattern match on type and the type-checker will make use of that type:
val x : Any = "boop"
x match {
case y : String => do-something-stringy(y);
case z : Int => .... etc
}
I know in core.typed, a conditional will help the type checker to resolve the exact type. I tried to replicate this using core.match:
(ann do-something-stringy [String -> String])
(defn do-something-stringy [message]
(str "Hello " message))
;; Doesn't work
(ann do-things [Object -> String])
(defn do-things [foo]
(match [(type foo)]
[String] (do-something-stringy foo)
:else "Nope"))
This fails with an error:
Function do-something-stringy could not be applied to arguments:
Domains: String
Arguments: Object
Ranges: String
with expected type: String
Is there a way to get this to work using core.match?
Thanks!
Try dispatching on
classrather thantype. core.typed has no real support fortypedue to its weirdness around metadata.