[racket-users] Contracts for generic interfaces (or struct type properties?)
I'm running into trouble in trying to give contracts to methods from generic interfaces (in the sense of racket/generic) that assign blame to the implementor of a bad method implementation. This seems like it's probably a common problem, so I'm hoping a solution exists. For an example, consider the following: #lang racket (module string-server racket (require racket/generic) (provide gen:can-be-string can-be-string? (contract-out [to-string (-> any/c string?)] )) (define-generics can-be-string (to-string can-be-string) #:fast-defaults ([string? (define (to-string str) str)]))) (module buggy racket (require (submod ".." string-server)) (provide (struct-out buggy)) (struct buggy () #:methods gen:can-be-string [(define (to-string this) 'not-a-string)])) (require (submod "." string-server) (submod "." buggy)) (to-string (buggy)) This program raises an exception as expected, but blames the string-server module rather than the buggy module. The string-server module can deflect blame from itself by changing the contract of to-string to (-> (can-be-string/c [to-string (-> any/c string?)]) string?), but the result is even worse: now the error blames the enclosing module. The closest thing I've found to a solution is to abandon racket/generic and use a struct type property with a guard that performs lots of checks and eventually calls chaperone-procedure. Aside from being verbose and error-prone (in that it requires manually writing checks correctly rather than relying the contract system), it also doesn't really address the problem of blame, since errors from e.g. raise-arguments-error don't blame anything in particular. Is there a way to write the kind of contract I have in mind? Thanks, Philip -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Type Racket command-line #:ps causing type error
Cool thanks for the clarification Vincent! On Monday, May 22, 2017 at 9:39:15 AM UTC-7, Vincent St-Amour wrote: > Hi Kay, > > On Sun, 21 May 2017 23:30:50 -0500, > kay wrote: > > > > Hi Vincent, > > > > Thanks for fixing it. Is there a Github commit that you can refer me > > to? Or does Racket development actually happen on Github? > > Yes, Racket development does happen on github. > > The relevant commit is this one: > https://github.com/racket/typed-racket/commit/c0af5235d255ca1a9622249c0ca26ad5349ccefa > > > In addition, MORE IMPORTANTLY, now that it looks like a bug that I > > found, is there a workaround to this problem without waiting for a new > > release that contains the fix? > > I see two potential solutions here: > - You could use a nightly build (from pre.racket-lang.org) instead of a > released version, until 6.10 comes out (planned for July). > - You could use `require/typed` to import `parse-command-line` at the > type that you need. That's the procedure version of the `command-line` > syntax, which should support all the same options, but with a > different interface. Since it's a procedure, you can ascribe it a type > yourself. > > > How stable is Typed Racket? I know you guys are doing an awesome job > > and I really love it - but just trying to put my expectation right, as > > I'm totally new to TR and this is my first TR problem and I > > encountered this bug, leading me to wonder this question. > > I'll let Sam answer this one, or one of TR's users. :) > > In general, though, it's possible for TR to lag a bit behind untyped > Racket for some things. If a Racket function, say, gains an extra > keyword argument, we're usually pretty good at adding it to its type > quickly. Sometimes things fall through the cracks; #:ps must have been > one of them. > > Vincent > > > > > On Thursday, May 18, 2017 at 1:51:14 PM UTC-7, Vincent St-Amour wrote: > > > I just pushed a fix. Thanks for the report! > > > > > > Vincent > > > > > > > > > On Wed, 17 May 2017 01:47:11 -0500, > > > lu wrote: > > > > > > > > On Tuesday, May 16, 2017 at 12:47:37 AM UTC-7, kay wrote: > > > > > Hi I feel this might be a bug, can anyone confirm or suggest a fix? > > > > > > > > > > Here's a minimal usage of `command-line` form: > > > > > > > > > > ``` > > > > > #lang typed/racket > > > > > > > > > > (define *message* : (Parameterof (Listof String)) (make-parameter > > > > > '())) > > > > > (define *verbose* : (Parameterof Boolean) (make-parameter #f)) > > > > > > > > > > (define (parse-cmdline) > > > > > (command-line > > > > > #:program "q" > > > > > #:once-each > > > > > [("-v" "--verbose") "verbose mode" (*verbose* #t)] > > > > > #:ps "foo bar" ; < causing type error > > > > > #:args #{msg : String} (*message* msg))) > > > > > > > > > > (parse-cmdline) > > > > > ``` > > > > > > > > > > Note that it gives the below type error[1]. However, if you comment > > > > > out the line with #:ps, type check passes. > > > > > > > > > > I noticed that from the error prompt, for argument 3, the expected > > > > > Union type doesn't include 'ps. This leads me to think it might be a > > > > > bug. Please tell me it's not and there's a fix:) > > > > > > > > > > > > > > > [1]: type error: > > > > > > > > > > test.rkt:6:0: Type Checker: Polymorphic function `parse-command-line' > > > > > could not be applied to arguments: > > > > > Argument 1: > > > > > Expected: Path-String > > > > > Given:String > > > > > Argument 2: > > > > > Expected: (U (Listof String) (Vectorof String)) > > > > > Given:(Vectorof String) > > > > > Argument 3: > > > > > Expected: (Listof (Pairof (U 'final 'help-labels 'multi 'once-any > > > > > 'once-each) (Listof (Listof Any > > > > > Given:(List (List 'once-each (List (List String String) (-> Any > > > > > Void) (Listof (List String (List 'ps String)) > > > > > Argument 4: > > > > > Expected: (-> Any a ... a b) > > > > > Given:(-> Any String * Void) > > > > > Argument 5: > > > > > Expected: (Listof String) > > > > > Given:(List String) > > > > > > > > > > in: (define (parse-cmdline) (command-line #:program "q" #:once-each > > > > > (("-v" "--verbose") "verbose mode" (*verbose* #t)) #:ps "foo bar" > > > > > #:args msg (*message* msg))) > > > > > > > > Ping... can anyone help with this problem? > > > > > > > > -- > > > > 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 racket-users+unsubscr...@googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https:/
Re: [racket-users] raco docs error on macOS 10.12.5
Thank you for quick response! I will check the nightly. Vitaliy. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] raco docs error on macOS 10.12.5
Hi Vitaliy, I believe this should be fixed now, but the fix was not in 6.9, hence the error you're seeing. If you want to try it, you can get a nightly build at pre.racket-lang.org 6.10 is due in July, and will include the fix. Thanks for the report, and please do let us know if the problem persists on the nightly build. Vincent On Mon, 22 May 2017 08:24:58 -0500, Vitaliy Vlasov wrote: > > Hi all, > > running `raco docs` in the terminal on macOS 10.12.5 gives this: > > ➜ c raco docs > 0:65: execution error: "file:///Applications/Racket%20v6.9/doc/index.html" > doesn’t understand the “open location” message. (-1708) > browser-run: process execute failed: '(# "-e" "open > location \"file:///Applications/Racket%20v6.9/doc/index.html\"") > > I've installed Racket through Homebrew Cask formula. Can someone please point > me to the cause of the problem? Is something wrong with my installation? > > Thanks! > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Re: Type Racket command-line #:ps causing type error
Hi Kay, On Sun, 21 May 2017 23:30:50 -0500, kay wrote: > > Hi Vincent, > > Thanks for fixing it. Is there a Github commit that you can refer me > to? Or does Racket development actually happen on Github? Yes, Racket development does happen on github. The relevant commit is this one: https://github.com/racket/typed-racket/commit/c0af5235d255ca1a9622249c0ca26ad5349ccefa > In addition, MORE IMPORTANTLY, now that it looks like a bug that I > found, is there a workaround to this problem without waiting for a new > release that contains the fix? I see two potential solutions here: - You could use a nightly build (from pre.racket-lang.org) instead of a released version, until 6.10 comes out (planned for July). - You could use `require/typed` to import `parse-command-line` at the type that you need. That's the procedure version of the `command-line` syntax, which should support all the same options, but with a different interface. Since it's a procedure, you can ascribe it a type yourself. > How stable is Typed Racket? I know you guys are doing an awesome job > and I really love it - but just trying to put my expectation right, as > I'm totally new to TR and this is my first TR problem and I > encountered this bug, leading me to wonder this question. I'll let Sam answer this one, or one of TR's users. :) In general, though, it's possible for TR to lag a bit behind untyped Racket for some things. If a Racket function, say, gains an extra keyword argument, we're usually pretty good at adding it to its type quickly. Sometimes things fall through the cracks; #:ps must have been one of them. Vincent > On Thursday, May 18, 2017 at 1:51:14 PM UTC-7, Vincent St-Amour wrote: > > I just pushed a fix. Thanks for the report! > > > > Vincent > > > > > > On Wed, 17 May 2017 01:47:11 -0500, > > lu wrote: > > > > > > On Tuesday, May 16, 2017 at 12:47:37 AM UTC-7, kay wrote: > > > > Hi I feel this might be a bug, can anyone confirm or suggest a fix? > > > > > > > > Here's a minimal usage of `command-line` form: > > > > > > > > ``` > > > > #lang typed/racket > > > > > > > > (define *message* : (Parameterof (Listof String)) (make-parameter '())) > > > > (define *verbose* : (Parameterof Boolean) (make-parameter #f)) > > > > > > > > (define (parse-cmdline) > > > > (command-line > > > > #:program "q" > > > > #:once-each > > > > [("-v" "--verbose") "verbose mode" (*verbose* #t)] > > > > #:ps "foo bar" ; < causing type error > > > > #:args #{msg : String} (*message* msg))) > > > > > > > > (parse-cmdline) > > > > ``` > > > > > > > > Note that it gives the below type error[1]. However, if you comment out > > > > the line with #:ps, type check passes. > > > > > > > > I noticed that from the error prompt, for argument 3, the expected > > > > Union type doesn't include 'ps. This leads me to think it might be a > > > > bug. Please tell me it's not and there's a fix:) > > > > > > > > > > > > [1]: type error: > > > > > > > > test.rkt:6:0: Type Checker: Polymorphic function `parse-command-line' > > > > could not be applied to arguments: > > > > Argument 1: > > > > Expected: Path-String > > > > Given:String > > > > Argument 2: > > > > Expected: (U (Listof String) (Vectorof String)) > > > > Given:(Vectorof String) > > > > Argument 3: > > > > Expected: (Listof (Pairof (U 'final 'help-labels 'multi 'once-any > > > > 'once-each) (Listof (Listof Any > > > > Given:(List (List 'once-each (List (List String String) (-> Any > > > > Void) (Listof (List String (List 'ps String)) > > > > Argument 4: > > > > Expected: (-> Any a ... a b) > > > > Given:(-> Any String * Void) > > > > Argument 5: > > > > Expected: (Listof String) > > > > Given:(List String) > > > > > > > > in: (define (parse-cmdline) (command-line #:program "q" #:once-each > > > > (("-v" "--verbose") "verbose mode" (*verbose* #t)) #:ps "foo bar" > > > > #:args msg (*message* msg))) > > > > > > Ping... can anyone help with this problem? > > > > > > -- > > > 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 racket-users+unsubscr...@googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] raco docs error on macOS 10.12.5
Hi all, running `raco docs` in the terminal on macOS 10.12.5 gives this: ➜ c raco docs 0:65: execution error: "file:///Applications/Racket%20v6.9/doc/index.html" doesn’t understand the “open location” message. (-1708) browser-run: process execute failed: '(# "-e" "open location \"file:///Applications/Racket%20v6.9/doc/index.html\"") I've installed Racket through Homebrew Cask formula. Can someone please point me to the cause of the problem? Is something wrong with my installation? Thanks! -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Porting additional functions for vectors, sequences, hashes etc. to Typed Racket
On Monday, May 22, 2017 at 6:14:01 PM UTC+5:30, Matthias Felleisen wrote: > Could you list the functions you’re missing? > > > > > On May 22, 2017, at 5:38 AM, Sourav Datta wrote: > > > > Is there any ongoing or planned effort to port additional functions > > available for vectors, sequences etc. to TR? Many of these functions are > > very useful while writing code which uses things beyond normal Lists and it > > seems we have to manually require/typed for each individual program. > > Surprisingly, the additional functions for Strings (like string-append*) > > are available in TR even though they are not part of racket/base. And also, > > it does not show up in the TR documentation. > > > > Thanks. > > > > -- > > 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 racket-users+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. Ok, two things happened which made me confused about the "missing" functions. I had an older version of Racket installed and I found some sequence functions like sequence-map and sequence-fold gave top level type missing error. Then I switched to 6.9 and tried to sort a vector with vector-sort in TR which resulted in the same error. These made me think that 6.9 is missing those functions in TR. So, I can confirm I get the typed versions of sequence and all of vector functions except the vector-sort functions. I guess I'd have to require/type it. Also, hash-union and hash-union! functions have no TR equivalent. Sorry for not double checking! -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Porting additional functions for vectors, sequences, hashes etc. to Typed Racket
Could you list the functions you’re missing? > On May 22, 2017, at 5:38 AM, Sourav Datta wrote: > > Is there any ongoing or planned effort to port additional functions available > for vectors, sequences etc. to TR? Many of these functions are very useful > while writing code which uses things beyond normal Lists and it seems we have > to manually require/typed for each individual program. Surprisingly, the > additional functions for Strings (like string-append*) are available in TR > even though they are not part of racket/base. And also, it does not show up > in the TR documentation. > > Thanks. > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] Porting additional functions for vectors, sequences, hashes etc. to Typed Racket
Is there any ongoing or planned effort to port additional functions available for vectors, sequences etc. to TR? Many of these functions are very useful while writing code which uses things beyond normal Lists and it seems we have to manually require/typed for each individual program. Surprisingly, the additional functions for Strings (like string-append*) are available in TR even though they are not part of racket/base. And also, it does not show up in the TR documentation. Thanks. -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.