[racket-users] Unit order matters in `define-values/invoke-unit/infer`

2016-03-09 Thread Phil Nguyen
The program below complains that `x` is used before initialization. But if I change the linking order to `x@` before `y@`, it works fine. Is this an intended behavior or a bug? This is Racket v6.4.0.7 #lang racket (define-signature x^ (x)) (define-signature y^ (y)) (define-unit x@ (import)

[racket-users] `equal?`'s unintuitive behavior with parametric contracts

2016-03-23 Thread Phil Nguyen
In the following program, `(p? 1 1)` returns `#t` or `#f` depending on `p?` being called from the same or different module: #lang racket (module m racket (provide (contract-out [p? (parametric->/c (a) (a a . -> . boolean?))])) (define p? equal?) (p? 1 1)) (require 'm) (p? 1 1)

[racket-users] How to get around unintuitive unwrapping of a seal when passing parametric argument to contract's range-maker?

2018-01-16 Thread Phil Nguyen
The following function with its contract will crash because when composing the range (P x), the seal around x is already unwrapped: (define/contract f (parametric->/c (α) (->i ([x α] [P (α . -> . contract?)] [f (P) (->i ([x α]) (_ (x) (P x)

Re: [racket-users] How to get around unintuitive unwrapping of a seal when passing parametric argument to contract's range-maker?

2018-01-17 Thread Phil Nguyen
C-5, Robby Findler wrote: > > I am not sure, but my first guess would be that it is a bug in the > contract system (due to a lack of understanding of what to do by me), > not that it is impossible to do this with dynamic sealing. > > Robby > > > On Tue, Jan 16, 2018 at 2:

Re: [racket-users] How to get around unintuitive unwrapping of a seal when passing parametric argument to contract's range-maker?

2018-01-18 Thread Phil Nguyen
call to `P` in the range >> of the `->d`, when in principle one would want it to be in terms of calling >> `f` with a bad argument. But it does blame the right party. >> >> -Philip >> >> On Wed, Jan 17, 2018 at 8:52 AM, Robby Findler < >> ro...@eecs

Re: [racket-users] How to get around unintuitive unwrapping of a seal when passing parametric argument to contract's range-maker?

2018-01-18 Thread Phil Nguyen
f (parametric->/c (α) (α ((and/c α (λ (x) (printf "inspect x: ~a~n" x))) . -> . any/c) . -> . any/c)) (λ (x g) (g x))) (f 42 add1) On Thursday, January 18, 2018 at 8:53:03 AM UTC-5, Robby Findler wrote: > > On Thu, Jan 18, 2018 at 7:43 AM, Phil Nguyen > wro

[racket-users] What are most type cases of `=` for?

2018-04-07 Thread Phil Nguyen
The full type of `=` in Typed Racket has lots of cases, whose ranges are all `Boolean`. Are all cases before the default one `Number Number Number * -> Boolean` useful in any way, or they were just part of some automatic generation? It's not obvious to me that the preceding cases are useful, be

Re: [racket-users] What are most type cases of `=` for?

2018-04-07 Thread Phil Nguyen
Oh I see!! Propositions were just omitted when pretty printed on my side. Thanks Sam! -- 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...@g

[racket-users] Surprising slow-down of near tail-call: Potential missed optimization?

2018-10-01 Thread Phil Nguyen
(Racket 7.0) This program runs in no time: (define (sum n acc) (if (> n 0) (sum (- n 1) (+ acc n)) acc)) (collect-garbage) (collect-garbage) (collect-garbage) (time (sum 1000 0)) ; cpu time: 47 real time: 57 gc time: 0 ; 500500 This slightly modified program runs signif

[racket-users] Re: Surprising slow-down of near tail-call: Potential missed optimization?

2018-10-01 Thread Phil Nguyen
Actually nvm. Whoever wrote such macro could have just used `begin0` instead. On Monday, October 1, 2018 at 2:34:23 PM UTC-4, Phil Nguyen wrote: > > (Racket 7.0) This program runs in no time: > > (define (sum n acc) > (if (> n 0) > (sum (- n 1) (+ acc n)) >

[racket-users] Can I declare opaque type constructor in `require/typed`?

2019-03-09 Thread Phil Nguyen
I'm attempting to add type bindings for mutable sets. I can't reuse the existing `Setof` type constructor because it is covariant. Is it possible to declare an opaque new type constructor `Mutable-Setof` in the `require/typed` clause? Thanks. -- You received this message because you are subsc

[racket-users] Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread Phil Nguyen
With Racket 7.2, the following program takes >13 seconds to run on Windows, and <7 seconds on Linux either on Virtualbox on the same machine, or native Linux on another machine with slightly lower-powered processor: #lang racket/base (define (fact n) (if (zero? n) 1 (* n (fact (- n 1) (tim

Re: [racket-users] literals vs datum-literals in syntax-parse

2017-04-21 Thread Phil Nguyen
On Tuesday, January 10, 2017 at 4:34:41 PM UTC-5, Alexis King wrote: > Basically, the difference is as follows: #:literals compares > identifiers using free-identifier=?, but #:datum-literals compares > them by using syntax-e and eq?. > > You can observe the difference using two extremely simple m

Re: [racket-users] TR for fast manipulation of C data

2017-09-17 Thread Phil Nguyen
Simply changing all the casts (cast _ Natural) into (assert _ exact-nonnegative-integer?), and (cast _ Positive-Flonum) into (assert (assert _ flonum?) positive?) speeds up significantly for me. On Sun, Sep 17, 2017 at 9:11 PM, Robby Findler wrote: > Maybe a first step is to just (unsafely) disa

Re: [racket-users] TR for fast manipulation of C data

2017-09-17 Thread Phil Nguyen
(and (cast _ Positive-Fixnum) into (assert (assert _ fIxnum?) positive?)). Somehow these make a huge difference.) On Sun, Sep 17, 2017 at 9:19 PM, Phil Nguyen wrote: > Simply changing all the casts (cast _ Natural) into (assert _ > exact-nonnegative-integer?), and (cast _ Positive-Flonum

Re: [racket-users] TR for fast manipulation of C data

2017-09-17 Thread Phil Nguyen
ep 17, 2017 at 9:39 PM, Sam Tobin-Hochstadt wrote: > `cast` uses the contract system, which is harder for the compiler to > optimize than `assert` which is just an if. At least that's my initial > impression. > > Sam > > On Sep 17, 2017 9:27 PM, "Phil Nguyen"

[racket-users] JSON type provider (ish) for Typed Racket

2019-08-14 Thread Phil Nguyen
Github repo: https://github.com/philnguyen/json-type-provider I read this PLDI 2016 paper about Type Provider for F# and attempted to implement it as a Racket macro. Then I realized it worked great in F# mostly because of dot notation and IDE

Re: [racket-users] Re: Working with JSON using Typed Racket

2020-04-08 Thread Phil Nguyen
For parsing JSON in Typed Racket, you can check out this library I made: https://github.com/philnguyen/json-type-provider . You can declare structs and field names that match the underlying data, and get back a well-typed parser. Don't let the name "type provider" fool you though, it's nothing