Re: [racket-users] how to use union types

2019-03-01 Thread Matthias Felleisen
. . . all of which suggests that perhaps we should support blazingly fast list chaperones eventually :) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racke

Re: [racket-users] how to use union types

2019-02-28 Thread Ben Greenman
On 2/28/19, Brian Craft wrote: > So, when working with large data that is internal to an app, where schema > is guaranteed by serialization, there's no way to load that without another > O(N) pass to satisfy the type checker? Right. This is how the type checker helps find & prevent bugs. There's

Re: [racket-users] how to use union types

2019-02-28 Thread jackhfirth
There is, but it's called "wrap your data in a struct". The type checker doesn't know that serialization guarantees your schema, and you haven't proved that *only* previously-serialized data will be constructed. In order to represent this knowledge with types, you can create a struct wrapper in

Re: [racket-users] how to use union types

2019-02-28 Thread Brian Craft
So, when working with large data that is internal to an app, where schema is guaranteed by serialization, there's no way to load that without another O(N) pass to satisfy the type checker? On Thursday, February 28, 2019 at 1:03:48 PM UTC-8, Sam Tobin-Hochstadt wrote: > > Yes, a cast to a List

Re: [racket-users] how to use union types

2019-02-28 Thread Sam Tobin-Hochstadt
Yes, a cast to a List type checks all the elements of the list. There's no way to tell if every element of list is a string in less than O(N) time -- that information just isn't available anywhere. Sam On Thu, Feb 28, 2019 at 3:52 PM Brian Craft wrote: > > Really? A cast is also O(N)? > > On Thu

Re: [racket-users] how to use union types

2019-02-28 Thread Brian Craft
Really? A cast is also O(N)? On Thursday, February 28, 2019 at 11:11:01 AM UTC-8, Sam Tobin-Hochstadt wrote: > > Any of these solutions need a O(N) traversal of the data. That's > because we need to do a full traversal to be sure we got an actual > (Listof String) from read-json -- there's no w

Re: [racket-users] how to use union types

2019-02-28 Thread Sam Tobin-Hochstadt
Any of these solutions need a O(N) traversal of the data. That's because we need to do a full traversal to be sure we got an actual (Listof String) from read-json -- there's no way around it. Sam On Thu, Feb 28, 2019 at 2:04 PM Brian Craft wrote: > > I would think there'd be a large performance

Re: [racket-users] how to use union types

2019-02-28 Thread Brian Craft
I would think there'd be a large performance issue, as well, due to needing an O(N) walk of the data. I'm having type checker issues with (time), so haven't tested it, but maybe (cast) will get me past those. Thanks! On Monday, February 25, 2019 at 4:26:52 PM UTC-8, Philip McGrath wrote: > > An

Re: [racket-users] how to use union types

2019-02-25 Thread Philip McGrath
An alternative to figuring out how to satisfy the type checker is to use `cast`, e.g.: #lang typed/racket (require typed/json) (string-join (cast (string->jsexpr "[\"The\",\"quick\",\"brown\",\"fox\",\"...\"]") (Listof String))) Obviously this has pros and cons, the main pro being that it

Re: [racket-users] how to use union types

2019-02-25 Thread jackhfirth
A JSExpr is one of a couple of things: - A list - A hash with symbol keys - A number - A string - A boolean - Null The (andmap string?) approach implicitly assumes you're giving it a list. But it might be something else instead, so you want this: (and (list? js) (andmap string? js)) On Monday,

Re: [racket-users] how to use union types

2019-02-25 Thread Sam Tobin-Hochstadt
That's because you don't necessarily have a list there, so you need to combine it with a list? check. Sam On Mon, Feb 25, 2019, 6:44 PM Brian Craft wrote: > So, that also gives me a type error: > > Type Checker: Polymorphic function `andmap' could not be applied to > arguments: > Domains: (->

Re: [racket-users] how to use union types

2019-02-25 Thread Brian Craft
So, that also gives me a type error: Type Checker: Polymorphic function `andmap' could not be applied to arguments: Domains: (-> a b ... b c) (Listof a) (Listof b) ... b (-> a c : d) (Listof a) Arguments: (-> Any Boolean : String) (U EOF JSExpr) in: (andmap string? s) On Monday, Fe

Re: [racket-users] how to use union types

2019-02-25 Thread Sam Tobin-Hochstadt
I think (andmap string? ...) is probably the easiest way to check that. Sam On Mon, Feb 25, 2019, 6:20 PM Brian Craft wrote: > In typed racket, parsing a string list gives me a JSExpr, which is a > union. I need to pass it to functions that operate on string lists, but > can't figure out how to

[racket-users] how to use union types

2019-02-25 Thread Brian Craft
In typed racket, parsing a string list gives me a JSExpr, which is a union. I need to pass it to functions that operate on string lists, but can't figure out how to please the type checker. Maybe with occurrence typing? But I don't know how to assert "this is a list of strings". -- You receive