Oh I should add that pred in Typed ClojureScript is partially implemented at the moment.
Thanks, Ambrose On Wed, Oct 29, 2014 at 8:27 PM, Ambrose Bonnaire-Sergeant < [email protected]> wrote: > On Wed, Oct 29, 2014 at 1:56 PM, Colin Yates <[email protected]> > wrote: > >> Hi Ambrose, >> >> I see, so a way to proceed is type the whole of the front end, but where >> we consume the server response we are on our own. >> > > It's more that checking the server response requires expressive contracts > that core.typed doesn't provide yet. > > If you expect the response to be a simple map, something like this can be > fully in typed land. > > (defalias Res > (HMap :mandatory {:a Int :b Str} > :optional {:c (U nil Str)})) > > (ann response [Str -> Res]) > (defn response [s] > {:post [((pred Res) %)]} > (read-string s)) > > One thing that's cool about Schema is that it coerces data as well as > validating. It's theoretically possible that core.typed could capture the > different ways Schema could coerce data in a static type signature, but I > haven't seriously tried to implement this. > > >> You mention predicates, can I infer from that that run-time enforcement >> of said types is not something that happens unless we explicitly make it >> happen (using the predicate)? > > > Correct, core.typed does not change your code. > > >> Assuming everything everywhere is typed sufficiently I guess the only >> place that predicate is needed is on the typed/untyped boundary. >> > > You can also use predicates to cast to a more specific type in typed land > (as above). > > (let [a :- Any, 1 > ;; a is Any > _ (assert ((pred Int) a)) > ;; a is Int > ] > (inc a)) > > Thanks, > Ambrose > > >> >> On Wednesday, 29 October 2014 17:05:23 UTC, Ambrose Bonnaire-Sergeant >> wrote: >> > Hi Colin, >> > >> > >> > The ClojureScript port is still in progress. >> > >> > >> > The story for casting values from untyped to typed land is >> non-existent. You basically >> > need to tell core.typed what types you're expecting from untyped land >> > with an unchecked annotation, and it's up to you to make sure those >> > assumptions are correct. >> > >> > >> > This is a major problem that will be tackled at some point during my >> PhD. >> > >> > >> > The closest thing right now to what you might want is >> clojure.core.typed/pred, which turns >> > a type into a predicate. >> > >> > >> > Then (do (assert ((pred Foo) x) x) can cast your value. >> > >> > >> > Otherwise you might want to use something like Schema at the >> typed/untyped boundaries to >> > validate data before they travel into typed land. But this is not a >> particularly pleasant workflow. >> > >> > >> > Thanks, >> > Ambrose >> > >> > >> > On Wed, Oct 29, 2014 at 12:42 PM, Colin Yates <[email protected]> >> wrote: >> > I am thinking of using core.typed for the clojurescript layer but after >> reading the docs it isn't clear to me how core.typed works in relation to >> serialisation. >> > >> > >> > >> > I get that core.typed does some static analysis at compile time, but >> what about runtime? What happens when I deserialise from a blob returned >> from the server, does it take it on faith that the defined typed contract >> is valid? >> > >> > >> > >> > Or, is the only option to type that as returning Any, in which case how >> on earth is it used? >> > >> > >> > >> > My intention is to describe the structure of the various data >> structures flying around the front end and consumed from the server with >> core.typed if that helps. >> > >> > >> > >> > Thanks! >> > >> > >> > >> > -- >> > >> > Note that posts from new members are moderated - please be patient with >> your first post. >> > >> > --- >> > >> > You received this message because you are subscribed to the Google >> Groups "ClojureScript" group. >> > >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to [email protected]. >> > >> > To post to this group, send email to [email protected]. >> > >> > Visit this group at http://groups.google.com/group/clojurescript. >> >> -- >> Note that posts from new members are moderated - please be patient with >> your first post. >> --- >> You received this message because you are subscribed to the Google Groups >> "ClojureScript" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/clojurescript. >> > > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
