Expressing hierarchy in function arguments

19 views
Skip to first unread message

Steven Benjamin

unread,
Aug 6, 2015, 4:15:23 PM8/6/15
to core.typed
Hi,
Is it possible to express the notion of a relationship between function argument and return values? For example, given a bunch of types that just represent maps which are progressively larger supersets, express a function that will return a larger set:

Something like (this doesn't work but should express the idea)

(t/defalias Base (t/HMap :mandatory {:s String }))
(t/defalias WithN (I Base '{:n Number}))

(t/ann my-function (t/All [[x <: Base ] [ y <: x ]] [ x -> y ])


It seems reasonable but I'm having difficulty locating applicable examples.

Thanks,
Steve Benjamin


Ambrose Bonnaire-Sergeant

unread,
Aug 7, 2015, 12:16:58 AM8/7/15
to core.typed
Hi,

Can you be more specific about what you're trying to achieve, like the definition
of my-function and what kinds of invocations you'd expect to be achievable?

Thanks,
Ambrose

Steven Benjamin

unread,
Aug 7, 2015, 10:38:59 AM8/7/15
to core.typed
Hi,
I've actually worked around this particular issue, and the question has become a bit academic. But basically I was trying to see if I could express something like inheritance - i.e. given some basic types in a hierarchy

(t/defalias Base (t/HMap :mandatory {:s String }))
(t/defalias Child1 (I Base '{n; Number}))
(t/defalias Child2 (I Base '
{s2; String}))
...
(t/defalis ChildN ...

be able to express something like a function that returns a wider type, something like

Base -> U (Child1 Child2 .... ChildN)

but generically. In that sense I wanted to see if you could declare a relationship generically between the type arguments, thus the 


(t/All [[x <: Base ] [ y <: x ]]


So on one level I was just trying to understand syntax. But looking at this now it occurs to me that this is trying to make core-typed behave like a scala (or java) generic hierarchy, and is probably thinking about it the wrong way.

One thing this does bring up is that it's not clear to me what "<:" means - is this synonymous with java inheritance? does it apply to things like purely core-typed concepts like intersections? 

Thanks,
Steve

Reply all
Reply to author
Forward
0 new messages