'Inheritence' of map based hierarchy

13 views
Skip to first unread message

Colin Yates

unread,
Mar 9, 2015, 12:49:13 PM3/9/15
to clojure-c...@googlegroups.com
I have an abstract type of 'command' and a number of sub types, only they are all expressed as maps not defrecords. 

At the moment I have:

(t/defalias CommandSchema (t/HMap :mandatory {:type Keyword}))

and

(t/defalias SayHelloSchema (t/HMap :mandatory {:type :say-hello :to-whom String}))

is there any way I can express and enforce that SayHelloSchema is-a (even if only structurally) with CommandSchema?

The *only* reason I ask is to capture that relationship - things that need a CommandSchema take a CommandSchema, things that expect a SayHelloSchema take one of those, it would just be nice to capture that relationship.

Thanks

Ambrose Bonnaire-Sergeant

unread,
Mar 9, 2015, 1:07:38 PM3/9/15
to core.typed
Something like (fn [m :- SayHellowSchema] :- CommandSchema, m) would work :)

Colin Yates

unread,
Mar 9, 2015, 1:10:59 PM3/9/15
to clojure-c...@googlegroups.com
Isn't that stating the function consumes a SayHelloSchema and returns a CommandSchema or am I confused?

Ambrose Bonnaire-Sergeant

unread,
Mar 9, 2015, 1:34:04 PM3/9/15
to core.typed
That just says a value that is of type SayHelloSchema is also a CommandSchema.
Reply all
Reply to author
Forward
0 new messages