[racket-users] join-based tree operations and racket-cs futures

2019-12-11 Thread Jon Zeppieri
I've been playing around with a simple AVL tree that uses the
split/join operations that Adams originally applied to weight-balanced
binary trees[1] and then Blelloch, Ferizovic, and Sun later applied to
other kinds of balanced binary trees.[2] The latter paper concentrates
on how certain operations (union, intersection, difference) are easily
parallelized with an implementation that uses this approach. In their
tests, they saw performance increase linearly up to around 32 cores.

I tried the same thing with futures on racket-cs (since I understand
that it has fewer blocking/synchronized operations than racket-c). On
my 8 core machine, performance is slightly better for a parallel
version of `union` (which is implemented exactly as Blelloch et al.
have it on the second page of their paper) but it's nowhere near a
linear speed-up. The parallel version completes a test in about 80% of
the time that the sequential version does.

The future-visualizer doesn't show any synchronizing or blocking
events (aside from the touches), though I also don't entirely
understand what it does show. What, for example, is indicated by a
thread that has only a very short green horizontal line? Is it just
idle for most of the time?

I'm using futures pretty much the same way that Dominik Pantůček is
using them in his `futures-sort` package, with a parallelism depth
computed from the number of cores available.[3] (Thank you for the
excellent example, by the way, Dominik.)

[1] http://groups.csail.mit.edu/mac/users/adams/BB/
[2] https://www.cs.cmu.edu/~guyb/papers/BFS16.pdf
[3] https://github.com/dzoep/futures-sort/blob/master/main.rkt#L338

My own code has:

(define (parallel-union t1 t2 cmp)
  (let loop ([t1 t1] [t2 t2] [depth (inexact->exact (ceiling (log
(processor-count) 2)))])
(match* (t1 t2)
  [(#f _) t2]
  [(_ #f) t1]
  [(_ (node _ l2 (and (cons k2 _) kv2) r2))
   (define-values (l1 _ r1) (split t1 k2 cmp))
   (cond
 [(fx<= depth 0)
  (define tl (loop l1 l2 (fx- depth 1)))
  (define tr (loop r1 r2 (fx- depth 1)))
  (join tl kv2 tr)]
 [else
  (define tl (future (λ () (loop l1 l2 (fx- depth 1)
  (define tr (loop r1 r2 (fx- depth 1)))
  (join (touch tl) kv2 tr)])])))

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAKfDxxyUaPFf6Kdum-FuKYunGrPCLsQxMZd3%3D4NR5k5MLqj6yg%40mail.gmail.com.


Re: [racket-users] How to use dates (especially gregor) with Typed Racket?

2019-12-11 Thread Ben Greenman
Thanks for the feedback! I opened a pull request for the docs:

https://github.com/racket/typed-racket/pull/886

Happy to continue the discussion over there.
(The example I added to the guide is maybe too simple.)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R6NDSWY5vBBiVON8PBR_vPREYEN8wNzXRyvqEsgn2OWuQ%40mail.gmail.com.


Re: [racket-users] Why is racklog so inefficient?

2019-12-11 Thread Sam Tobin-Hochstadt
Racklog is a port to more-idiomatic Racket of the Schelog system [1]
by Dorai Sitaram. The idea of Schelog was not to be a high-performance
implementation of Prolog, but to use continuations to allow smooth
integration between Prolog-style search and more conventional
computation, while maintaining a simple implementation. Maintaining
this integration (see
https://docs.racket-lang.org/racklog/racket-w-logic.html) with a
WAM-based system would be tricky. Additionally, since Racklog is not
widely used currently, I think there hasn't been much of a push to
optimize it.

Because Racklog uses continuations, I expect that it runs much faster
on Racket CS, which has a much more efficient implementation of
continuations than the traditional Racket VM.

Building a new and efficient Prolog implementation in Racket would be
a great thing to do, and I encourage you to do this, or even just to
start by porting the Common Lisp code you have.

Sam

On Wed, Dec 11, 2019 at 4:42 PM Eduardo Costa  wrote:
>
> From time to time, I test Racklog, in the hope that the Racket team replaced 
> it with something more efficient. After all, there are many good 
> implementations of Prolog like languages around. I simply cannot understand 
> why Racket must be packed with a ridiculously slow piece of software, such as 
> Racklog. Therefore, in order to discover how difficult would be the 
> implementation of an efficient version of Racklog, I decided to check what I 
> could do in Common Lisp. The reason for choosing Common Lisp is that there 
> are a few inference machines in Lisp, so I did not need to start from scratch.
>
> I found a book by Patrice Boizumalt that explained how to implement  Prolog; 
> the examples are in Common Lisp. I also found the material published in 
> Japanese by Daiki Matsunaga from the Kioto Institute of Technology. The 
> implementations of Boizumalt and Matsunaga are incomplete. For instance, they 
> did not implement floating point. It took me about one hour to complete their 
> implementations. Besides this, both implementations had bugs, which I fixed, 
> and raised an issue on the github pages of the authors. Finally, I tested the 
> programs with small grammars, puzzles and loops, just to check the tail call 
> optimization. Here is the comparison between Matsunaga's Prolog and cxprolog:
>
> ```
> %% File: again.pl
> › cat again.pl
>
> loop(0, Acc, Acc) :- !.
> loop(N, Acc, F) :- A1 is Acc + 0.1, N1 is N - 1, loop(N1, A1, F).
> ```
>
> Here is the execution in cxprolog:
>
> ```
> ~/wrkLisp/wam
> › ./cxp
> CxProlog version 0.98.2 [development]
>
> [main] ?- consult('again.pl').
> % File 'again.pl' consulted, 0.000106 sec 2768 bytes
> yes
>
> [main] ?- X1 is cputime, loop(200, 0.1, F), T is cputime - X1.
> X1 = 0.050186
> F = 20.1
> T = 133.843561
> ```
>
> So, cxprolog executed 2 millions of repetitions in about 130 seconds. By the 
> way, cxprolog is written in c. Now, here is the execution of Matsunaga's 
> Prolog, which is written in Lisp:
>
> ```
> ~/wrkLisp/wam› rlwrap ros run
> * (load "wam.lisp")
> T
> * (repl)
> * (repl)
> > ?- consult('again.pl').
>
> yes.
> > ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
> F = 197024.88
> X1 = 3804
> X2 = 11729
> T = 7925
>
> yes.
> > ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
> F = 197024.88
> X1 = 11730
> X2 = 19832
> T = 8102
>
> yes.
> > ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
> F = 197024.88
> X1 = 19833
> X2 = 28478
> T = 8645
>
> yes.
> ```
>
> I added floating point and the predicate cputime(X) to Matsunaga's code, and 
> corrected a few bugs. The modified program is about 16 times faster than 
> cxprolog. Matsunaga wrote an interpreter, in order to execute code for the 
> Warren Abstract Machine. Of course, the is very inefficient. Therefore, I 
> expanded each instruction that appear in the code into Lisp programs. 
> Consider the code below, that Matsunaga's interpreter executes. I created a 
> Lisp definition for the loop predicate, where I expanded each definition, 
> according to what appears in the interpreter. Thus, the Lisp code became 
> considerably faster than the cxprolog code.  I did this in about one day. 
> Here is my question: Since it is so easy to write an efficient Prolog in 
> Lisp, why the Racket community insists in using Racklog? I would like to 
> propose a project to implement an efficient version of Racklog, based in 
> Matsunaga's version of the Warren Abstract Machine. The first step is to fix 
> all bugs that still remain in the Lisp version, and expand the instructions 
> to eliminate the necessity of the interpreter. After obtaining a flawless 
> Lisp version, one can prepare a Scheme/Racket version.
>
> ```
> * (gethash (cons '|loop| 3) *dispatching-code-table*)
> ((TRY-ME-ELSE #:G525
>   ((TRUST-ME) (ALLOCATE) (GET-VARIABLE-PERMANENT 4 1)
>(GET-VARIABLE-PERMANENT 3 3) (PUT-VARIABLE-PERMANENT 2 1)
>(PUT-CONSTANT 0.1 3) (CALL 

[racket-users] Why is racklog so inefficient?

2019-12-11 Thread Eduardo Costa
>From time to time, I test Racklog, in the hope that the Racket team 
replaced it with something more efficient. After all, there are many good 
implementations of Prolog like languages around. I simply cannot understand 
why Racket must be packed with a ridiculously slow piece of software, such 
as Racklog. Therefore, in order to discover how difficult would be the 
implementation of an efficient version of Racklog, I decided to check what 
I could do in Common Lisp. The reason for choosing Common Lisp is that 
there are a few inference machines in Lisp, so I did not need to start from 
scratch.

I found a book by Patrice Boizumalt that explained how to implement  
Prolog; the examples are in Common Lisp. I also found the material 
published in Japanese by Daiki Matsunaga from the Kioto Institute of 
Technology. The implementations of Boizumalt and Matsunaga are incomplete. 
For instance, they did not implement floating point. It took me about one 
hour to complete their implementations. Besides this, both implementations 
had bugs, which I fixed, and raised an issue on the github pages of the 
authors. Finally, I tested the programs with small grammars, puzzles and 
loops, just to check the tail call optimization. Here is the comparison 
between Matsunaga's Prolog and cxprolog:

```
%% File: again.pl
› cat again.pl

loop(0, Acc, Acc) :- !.
loop(N, Acc, F) :- A1 is Acc + 0.1, N1 is N - 1, loop(N1, A1, F).
```

Here is the execution in cxprolog:

```
~/wrkLisp/wam
› ./cxp
CxProlog version 0.98.2 [development]

[main] ?- consult('again.pl').
% File 'again.pl' consulted, 0.000106 sec 2768 bytes
yes

[main] ?- X1 is cputime, loop(200, 0.1, F), T is cputime - X1.
X1 = 0.050186
F = 20.1
T = 133.843561
```

So, cxprolog executed 2 millions of repetitions in about 130 seconds. By 
the way, cxprolog is written in c. Now, here is the execution of 
Matsunaga's Prolog, which is written in Lisp:

```
~/wrkLisp/wam› rlwrap ros run
* (load "wam.lisp")
T
* (repl)
* (repl)
> ?- consult('again.pl').

yes.
> ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
F = 197024.88
X1 = 3804
X2 = 11729
T = 7925

yes.
> ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
F = 197024.88
X1 = 11730
X2 = 19832
T = 8102

yes.
> ?- cputime(X1), loop(200, 0.1, F), cputime(X2), T is X2 - X1.
F = 197024.88
X1 = 19833
X2 = 28478
T = 8645

yes.
```

I added floating point and the predicate cputime(X) to Matsunaga's code, 
and corrected a few bugs. The modified program is about 16 times faster 
than cxprolog. Matsunaga wrote an interpreter, in order to execute code for 
the Warren Abstract Machine. Of course, the is very inefficient. Therefore, 
I expanded each instruction that appear in the code into Lisp programs. 
Consider the code below, that Matsunaga's interpreter executes. I created a 
Lisp definition for the loop predicate, where I expanded each definition, 
according to what appears in the interpreter. Thus, the Lisp code became 
considerably faster than the cxprolog code.  I did this in about one day. 
Here is my question: Since it is so easy to write an efficient Prolog in 
Lisp, why the Racket community insists in using Racklog? I would like to 
propose a project to implement an efficient version of Racklog, based in 
Matsunaga's version of the Warren Abstract Machine. The first step is to 
fix all bugs that still remain in the Lisp version, and expand the 
instructions to eliminate the necessity of the interpreter. After obtaining 
a flawless Lisp version, one can prepare a Scheme/Racket version.

```
* (gethash (cons '|loop| 3) *dispatching-code-table*)
((TRY-ME-ELSE #:G525
  ((TRUST-ME) (ALLOCATE) (GET-VARIABLE-PERMANENT 4 1)
   (GET-VARIABLE-PERMANENT 3 3) (PUT-VARIABLE-PERMANENT 2 1)
   (PUT-CONSTANT 0.1 3) (CALL (|plus| . 3) 4) (PUT-VARIABLE-PERMANENT 1 1 4)
   (PUT-UNSAFE-VALUE 4 2) (PUT-CONSTANT 1 3) (CALL (|minus| . 3) 3)
   (PUT-UNSAFE-VALUE 1 1 3) (PUT-UNSAFE-VALUE 2 2) (PUT-UNSAFE-VALUE 3 3)
   (DEALLOCATE) (EXECUTE (|loop| . 3
 (GET-CONSTANT 0 1) (GET-VALUE-TEMPORARY 2 3) (NECK-CUT) (PROCEED)
 (LABEL #:G525) (TRUST-ME) (ALLOCATE) (GET-VARIABLE-PERMANENT 4 1)
 (GET-VARIABLE-PERMANENT 3 3) (PUT-VARIABLE-PERMANENT 2 1) (PUT-CONSTANT 
0.1 3)
 (CALL (|plus| . 3) 4) (PUT-VARIABLE-PERMANENT 1 1 4) (PUT-UNSAFE-VALUE 4 2)
 (PUT-CONSTANT 1 3) (CALL (|minus| . 3) 3) (PUT-UNSAFE-VALUE 1 1 3)
 (PUT-UNSAFE-VALUE 2 2) (PUT-UNSAFE-VALUE 3 3) (DEALLOCATE)
 (EXECUTE (|loop| . 3)))

* (show-wamcode "loop" 3)
  try-me-else G525
  get-constant 0,A1
  get-value X2,A3
  neck-cut
  proceed
G525: trust-me
  allocate
  get-variable Y4,A1
  get-variable Y3,A3
  put-variable Y2,A1
  put-constant 0.1,A3
  call plus/3,4
  put-variable Y1,A1
  put-unsafe-value Y4,A2
  put-constant 1,A3
  call minus/3,3
  put-unsafe-value Y1,A1
  put-unsafe-value Y2,A2
  

Re: [racket-users] Racket 7.5 DMG file does not open on OSX 10.11

2019-12-11 Thread David Storrs
Brilliant.  Downloaded, installed, works great.  Thanks, Matthew.

On Wed, Dec 11, 2019 at 11:00 AM Matthew Flatt  wrote:

> At the moment, we don't have plans to rebuild v7.5, so the change would
> kick in with v7.6.
>
> The snapshot builds use HFS+ --- but they did, anyway, since they're
> created with an older version of Mac OS.
>
> At Wed, 11 Dec 2019 10:45:08 -0500, David Storrs wrote:
> > Thanks, Matthew,
> >
> > The version on the downloads page seems to still be APFS.  Will it
> rebuild
> > at some point?
> >
> > On Tue, Dec 10, 2019 at 8:46 PM Matthew Flatt 
> wrote:
> >
> > > I’ve changed the distribution build to use HFS+ going forward.
> > >
> > > > On Dec 10, 2019, at 6:28 PM, James Platt  wrote:
> > > >
> > > >
> > > >> On Dec 6, 2019, at 9:56 PM, Darth Vadør wrote:
> > > >>
> > > >> If it isn't too much trouble, I at least would really appreciate
> this.
> > > >> One reason I think this is important is because Homebrew has a cask
> for
> > > Racket, which uses the .dmg distribution. It sets up $PATH (and
> probably
> > > other things I don't know about as well), and can update Racket for
> you,
> > > which is quite pleasant.
> > > >>
> > > >> If the maintainers of the cask see there is an easy way to support
> > > older Macs they might (fingers crossed) consider it.
> > > >
> > > > I would also like to have an HFS+ formatted dmg as an option.
> However,
> > > Homebrew has dropped support for El Capitan and earlier but it
> continues to
> > > work (most of the time) if you already had a previous version
> installed.
> > > Everything after El Capitan can read APFS.   So, the maintainers of the
> > > cask might decide that any new legacy support would be short lived.
> > > >
> > > > --
> > > > 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.
> > > > To view this discussion on the web visit
> > >
> >
> https://groups.google.com/d/msgid/racket-users/EDDD1A40-9C10-4F2B-8A07-6933784C
> > 5C41%40biomantica.com
> > > .
> > > >
> > >
> > > --
> > > 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.
> > > To view this discussion on the web visit
> > >
> >
> https://groups.google.com/d/msgid/racket-users/FFE82A21-AE9E-49F0-9F55-76E47C32
> > D58B%40cs.utah.edu
> > > .
> > >
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKodtpvogzSfTzhBB2Z-ykHk%3Du78qS6Z-QO_%2BMX6Mc4ZU1Q%40mail.gmail.com.


Re: [racket-users] How to use dates (especially gregor) with Typed Racket?

2019-12-11 Thread Marc Kaufmann


On Saturday, December 7, 2019 at 3:04:25 PM UTC+1, Ben Greenman wrote:
>
> On 12/7/19, Marc Kaufmann > wrote: 
> > Thanks Ben and Jon, that did the trick. 
> > 
> > I realized when following the code that the structure wasn't exported - 
> but 
> > 
> > I didn't know how to work around that. I now also checked the 
> > documentation, and the only thing I found on opaque types is 
> > 
> https://docs.racket-lang.org/ts-reference/special-forms.html?q=opaque#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._require%2Ftyped%29%29.
>  
>
> > 
> > What it says about opaque types is: 
> > 
> > "Opaque types must be required lexically before they are used." 
>
> The docs says a little more --- there are 4 sentences that come right 
> before this one. 
>
> I think those sentences would be better off with: 
> 1. a link to `make-predicate` 
> 2. and English words at the start & end of each sentence 
>
> Let me know if you have other suggestions 
>

So here is the paragraph:

> The fourth case defines a new type t. pred, imported from module m, is a 
predicate for this type. The type is defined as precisely those values to 
which pred produces #t. pred must have type (Any -> Boolean). Opaque types 
must be required lexically before they are used.


When I came to the documentation, I was skimming, in part because I didn't 
know whether this would be helpful or not. I am not a fan of the "The 
first/second/... case..." when there are many cases and I can no longer see 
what the cases were - and in fact I miscounted the rows, so I thought this 
applied to something else for a while. Or rather, I like it, but only if it 
is 


"The fourth case defines a new *opaque* type t. ..."


When I got to the last sentence starting with 'Opaque types...', I had to 
think again to realize this is the fourth case talked about - even though 
no one at any point talked about opaque types, so I was wondering where I'd 
missed them.


Second sentence "This type t is defined via the predicate `pred`, imported 
from module m. More precisely, it is defined as precisely ... . 

>
> > followed by an example that is even now non-trivial for me to parse and 
> > figure out. (I started going down the rabbit hole when the `->` was not 
> > used in the first position of the definition, nor written as `. -> .` 
> Turns 
> > out types can be defined via infix notation, which is nice but 
> unexpected.) 
>
> The docs for -> show the infix notation. 
>

Yeah, I followed that and therefore realized that it was infix notation. 
Just to explain why I said it, even though I do *not* think that this 
particular instance should get changed: The point I was making is that for 
someone like me who doesn't live and breathe Racket, any extra layer of 
abstraction that isn't the same everywhere is extra cognitive load. Imagine 
me replacing every few words by a French word. I guess the fact that Racket 
contracts and Typed Racket don't use exactly the same notation is just a 
(very minor) nuisance. And I realize that it is incredibly hard to write 
helpful and clear documentation, so I'm not saying that I'd do a better job.

I only very recently started to be able to read and understand the Racket 
reference, while before I skipped all the arrow bits (and hence 
higher-order functions) and used the examples to reverse-engineer what form 
the arguments must take. That means that often I can't figure out what I 
need from the reference even when it's there. 


> Is the example still difficult to figure out? We could replace it, but 
> I'm not sure what could be better 
>
>
I think what I'd suggest is to add an example with #:opaque to the Typed 
Racket Guide, part 6 
(https://docs.racket-lang.org/ts-guide/typed-untyped-interaction.html). 

(if want to stop using infix notation here, then the other uses on the 
> same page need to change too) 
>
>
No, I think it's fine. 

> 
> > So there are two questions: 
> > 
> > 1. What does #:opaque do? 
> > 2. How could I have found that out by searching - or essentially the way 
> to 
> > 
> > do it was "Email the list". If the latter, that's fine, the email list 
> is 
> > very helpful and it would be good to add some additional explanation of 
> > opaque types to the documentation of `require-typed`, and possibly even 
> to 
> > the typed racket reference. Probably the part talking about typed-racket 
> > untyped racket interaction. 
> > 
> > Let me try answering my first question: #:opaque defines a new type via 
> a 
> > predicate function -- here `time?` -- that is being imported (can I use 
> it 
> > without require-typed? I guess there would be no point, but I haven't 
> > thought this through). This is not based on the usual type constructors 
> > using other types, but based on whether a thing returns `#true` when 
> passed 
> > to the predicate, in my case `time?`. I assume this means that the type 
> is 
> > verified via contracts, so if I do this a lot I should expect some 
> run-time 
> > 

Re: [racket-users] Typed Racket: 'Unable to protect opaque value passed as `Any`' with interesting behavior

2019-12-11 Thread Marc Kaufmann
Thanks. Yes, I realized that the two gave the same answer, but for 
debugging I tried to see if it was different. I think I now see where I am 
thinking about this in the wrong way. I thought `(U A B)` means 'it is 
either of type A or of type B', with the implication that it picks the more 
stringent one when possible. When there are two separate types A and B, 
this is innocuous enough, I think. What you are saying is that when typed 
racket sees `(U response Any)`, it transforms it (via some macro applied 
before doing type checking?) into `Any`. I thought it would leave `(U 
response Any)` around and always check against both, which is why I 
switched the order to see if that happened. 

A trivial and obvious answer to something that stumped me for quite a 
while. Good illustration of 

“It's not what we don't know that hurts. It's what we know that ain't so.”

Cheers,
Marc

On Wednesday, December 11, 2019 at 4:27:03 PM UTC+1, Sam Tobin-Hochstadt 
wrote:
>
> First, (U Any response) is the same as (U response Any) which is the 
> same as Any -- Any includes all other types and thus includes 
> response. 
>
> Second, f4 really is breaking the contract -- the contract Any turns 
> into says: don't try to pass through any "interesting" values, or if 
> you do, the other side isn't allowed to look at them. You passed a 
> "response" which is an interesting value (not a number or suchlike) 
> and the web server actually did something with it. The REPL doesn't 
> give you this error because in a typed module the REPL is also typed. 
>
> The problem is fundamentally that when you using Any in an annotation, 
> you're explicitly asking Typed Racket to throw away information. 
> Unfortunately, when you throw away that information for something that 
> you provide to untyped parts of your program, you've thrown away the 
> information Typed Racket needed to generate a more useful contract. So 
> instead, Typed Racket generates the best contract it can, which is as 
> described above. 
>
> Sam 
>
> On Wed, Dec 11, 2019 at 8:31 AM Marc Kaufmann  > wrote: 
> > 
> > Hello, 
> > 
> > I have one file called `type-test.rkt` with the following (notice that I 
> discovered that there is a typed version of the web-server/http module, 
> which solves another of my issues): 
> > 
> > ``` 
> > #lang typed/racket 
> > 
> > (require (only-in typed/web-server/http response/xexpr response)) 
> > 
> > (provide f1 f2 f3 f4) 
> > 
> > (: f1 (-> response)) 
> > (define (f1) 
> >   (define x '(body (h1 "Try it"))) 
> >   (: resp response) 
> >   (define resp (response/xexpr x)) 
> >   resp) 
> > 
> > (: f2 (-> (U response Any))) 
> > (define (f2) 
> >   (define x '(body (h1 "Try it"))) 
> >   (: resp response) 
> >   (define resp (response/xexpr x)) 
> >   resp) 
> > 
> > (: f3 (-> (U response Number))) 
> > (define (f3) 
> >   (define x '(body (h1 "Try it"))) 
> >   (: resp response) 
> >   (define resp (response/xexpr x)) 
> >   resp) 
> > 
> > (: f4 (-> (U Any response))) 
> > (define (f4) 
> >   (define x '(body (h1 "Try it"))) 
> >   (: resp response) 
> >   (define resp (response/xexpr x)) 
> >   resp) 
> > ``` 
> > 
> > Then I have another *untyped* file for a servlet: 
> > 
> > ``` 
> > #lang racket 
> > 
> > (require "type-test.rkt" 
> >  web-server/servlet 
> >  web-server/servlet-env) 
> > 
> > (define (start req) 
> >   (f1) 
> >   ; (f2) 
> >   ; (f3) 
> >   ; (f4) 
> >   ) 
> > 
> > (serve/servlet start 
> >#:servlet-regexp #rx"" 
> >#:launch-browser? #false 
> >#:port 8080) 
> > ``` 
> > 
> > Notice that I am telling all the f* functions that `resp` is of type 
> `response`. Yet, when I run the server with `start` using `f1` through `f4` 
> I get the following results: 
> > 
> > (f1): All good 
> > (f2): Error, see below. Unable to protect opaque value passed as `Any` 
> > (f3): All good 
> > (f4): Error, see below. 
> > 
> > The error is: 
> > 
> > ``` 
> > 
> > f4: broke its own contract 
> >   any-wrap/c: Unable to protect opaque value passed as `Any` 
> >   value: # 
> >   in: the range of 
> >   (-> Any) 
> > 
> > ``` 
> > 
> > First, I couldn't figure out how to replicate this in the REPL, and had 
> to use the server to get the result. But I was able to figure out at the 
> REPL that (f2) and (f4) return something of type `Any`, for some unknown 
> reason. Clearly TR is smart enough to figure out that `resp` is not a 
> Number, but a response, but then when I allow it to return both a type 
> `response` and `Any`, it says that it's return value is `Any`. Why? Every 
> function that can take `Any` can take `response`, and every function that 
> expects response is now going to blow up (as now happens). 
> > 
> > At the REPL, I didn't manage to get this behavior, probably because 
> `serve/servlet` has contracts around it's arguments. Thus: 
> > 
> > - I pass all the typed racket tests 
> > - I nonetheless return something of type `Any` (which is 

Re: [racket-users] Racket 7.5 DMG file does not open on OSX 10.11

2019-12-11 Thread Matthew Flatt
At the moment, we don't have plans to rebuild v7.5, so the change would
kick in with v7.6.

The snapshot builds use HFS+ --- but they did, anyway, since they're
created with an older version of Mac OS.

At Wed, 11 Dec 2019 10:45:08 -0500, David Storrs wrote:
> Thanks, Matthew,
> 
> The version on the downloads page seems to still be APFS.  Will it rebuild
> at some point?
> 
> On Tue, Dec 10, 2019 at 8:46 PM Matthew Flatt  wrote:
> 
> > I’ve changed the distribution build to use HFS+ going forward.
> >
> > > On Dec 10, 2019, at 6:28 PM, James Platt  wrote:
> > >
> > >
> > >> On Dec 6, 2019, at 9:56 PM, Darth Vadør wrote:
> > >>
> > >> If it isn't too much trouble, I at least would really appreciate this.
> > >> One reason I think this is important is because Homebrew has a cask for
> > Racket, which uses the .dmg distribution. It sets up $PATH (and probably
> > other things I don't know about as well), and can update Racket for you,
> > which is quite pleasant.
> > >>
> > >> If the maintainers of the cask see there is an easy way to support
> > older Macs they might (fingers crossed) consider it.
> > >
> > > I would also like to have an HFS+ formatted dmg as an option.  However,
> > Homebrew has dropped support for El Capitan and earlier but it continues to
> > work (most of the time) if you already had a previous version installed.
> > Everything after El Capitan can read APFS.   So, the maintainers of the
> > cask might decide that any new legacy support would be short lived.
> > >
> > > --
> > > 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.
> > > To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/racket-users/EDDD1A40-9C10-4F2B-8A07-6933784C
> 5C41%40biomantica.com
> > .
> > >
> >
> > --
> > 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.
> > To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/racket-users/FFE82A21-AE9E-49F0-9F55-76E47C32
> D58B%40cs.utah.edu
> > .
> >

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20191211160035.39C1F65019A%40mail-svr1.cs.utah.edu.


[racket-users] Using typed racket with web server continuations `(send/suspend/dispatch ...)`

2019-12-11 Thread Marc Kaufmann
Hi,

if possible, I'd like to use web server continuations with 
`(send/suspend/dispatch...)`. However, currently I need to return something 
of type `response?`, but when send/suspend/dispatch (and friends) don't 
return a response - they send it to the client and return `Any` (or other 
types). 

The question is: is this even possible to get working when my servlet 
expects a response back? And if not, is there some clever way to make it 
work anyway - typing things differently? I think that I won't go down the 
road of using different types, since sometimes I want to use a function 
that returns a response directly, rather than via web continuations.

The cod so far: 

```{module that creates the response}
#lang typed/racket

(require typed/web-server/http)
(define-type EmbedURL (-> (-> request Any) String))
(define-type ResponseMaker (-> EmbedURL response))

(require/typed web-server/servlet
   [send/suspend/dispatch (-> ResponseMaker Any)])

(define continuation-servlet
  (λ (req)
 (: response-generator ResponseMaker)
 (define (response-generator embed/url)
   (response/wrap-xexpr
 #:title text
 #:wrap-body? #t
 #:xexpr `(body (h1 ,text)
,(if when-done
   (next-button (λ () (when-done (state-response 
'next 'display-page)))
embed/url)
   '(p "Thanks and goodbye"))
)))
 (send/suspend/dispatch response-generator

```

which gets called elsewhere in a non-typed module via 
`(continuation-servlet req)`, which has the wrong type. I could simply 
claim that the returned type is response (it's thrown away anyway, I 
think), but that seems wrong at the conceptual level. 

Thanks for any pointers as to how to make this work - or why not to try to 
make it work.

Cheers,
Marc

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/58a6be81-2d68-4f3f-a621-cc01888db011%40googlegroups.com.


Re: [racket-users] Racket 7.5 DMG file does not open on OSX 10.11

2019-12-11 Thread David Storrs
Thanks, Matthew,

The version on the downloads page seems to still be APFS.  Will it rebuild
at some point?

On Tue, Dec 10, 2019 at 8:46 PM Matthew Flatt  wrote:

> I’ve changed the distribution build to use HFS+ going forward.
>
> > On Dec 10, 2019, at 6:28 PM, James Platt  wrote:
> >
> >
> >> On Dec 6, 2019, at 9:56 PM, Darth Vadør wrote:
> >>
> >> If it isn't too much trouble, I at least would really appreciate this.
> >> One reason I think this is important is because Homebrew has a cask for
> Racket, which uses the .dmg distribution. It sets up $PATH (and probably
> other things I don't know about as well), and can update Racket for you,
> which is quite pleasant.
> >>
> >> If the maintainers of the cask see there is an easy way to support
> older Macs they might (fingers crossed) consider it.
> >
> > I would also like to have an HFS+ formatted dmg as an option.  However,
> Homebrew has dropped support for El Capitan and earlier but it continues to
> work (most of the time) if you already had a previous version installed.
> Everything after El Capitan can read APFS.   So, the maintainers of the
> cask might decide that any new legacy support would be short lived.
> >
> > --
> > 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.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/EDDD1A40-9C10-4F2B-8A07-6933784C5C41%40biomantica.com
> .
> >
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/FFE82A21-AE9E-49F0-9F55-76E47C32D58B%40cs.utah.edu
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoe-rC-D2YHbn%3D89r8fYZug%2BXJx1OB4TtKOvgErSw%2BvN7g%40mail.gmail.com.


Re: [racket-users] Typed Racket: 'Unable to protect opaque value passed as `Any`' with interesting behavior

2019-12-11 Thread Sam Tobin-Hochstadt
First, (U Any response) is the same as (U response Any) which is the
same as Any -- Any includes all other types and thus includes
response.

Second, f4 really is breaking the contract -- the contract Any turns
into says: don't try to pass through any "interesting" values, or if
you do, the other side isn't allowed to look at them. You passed a
"response" which is an interesting value (not a number or suchlike)
and the web server actually did something with it. The REPL doesn't
give you this error because in a typed module the REPL is also typed.

The problem is fundamentally that when you using Any in an annotation,
you're explicitly asking Typed Racket to throw away information.
Unfortunately, when you throw away that information for something that
you provide to untyped parts of your program, you've thrown away the
information Typed Racket needed to generate a more useful contract. So
instead, Typed Racket generates the best contract it can, which is as
described above.

Sam

On Wed, Dec 11, 2019 at 8:31 AM Marc Kaufmann  wrote:
>
> Hello,
>
> I have one file called `type-test.rkt` with the following (notice that I 
> discovered that there is a typed version of the web-server/http module, which 
> solves another of my issues):
>
> ```
> #lang typed/racket
>
> (require (only-in typed/web-server/http response/xexpr response))
>
> (provide f1 f2 f3 f4)
>
> (: f1 (-> response))
> (define (f1)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f2 (-> (U response Any)))
> (define (f2)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f3 (-> (U response Number)))
> (define (f3)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f4 (-> (U Any response)))
> (define (f4)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
> ```
>
> Then I have another *untyped* file for a servlet:
>
> ```
> #lang racket
>
> (require "type-test.rkt"
>  web-server/servlet
>  web-server/servlet-env)
>
> (define (start req)
>   (f1)
>   ; (f2)
>   ; (f3)
>   ; (f4)
>   )
>
> (serve/servlet start
>#:servlet-regexp #rx""
>#:launch-browser? #false
>#:port 8080)
> ```
>
> Notice that I am telling all the f* functions that `resp` is of type 
> `response`. Yet, when I run the server with `start` using `f1` through `f4` I 
> get the following results:
>
> (f1): All good
> (f2): Error, see below. Unable to protect opaque value passed as `Any`
> (f3): All good
> (f4): Error, see below.
>
> The error is:
>
> ```
>
> f4: broke its own contract
>   any-wrap/c: Unable to protect opaque value passed as `Any`
>   value: #
>   in: the range of
>   (-> Any)
>
> ```
>
> First, I couldn't figure out how to replicate this in the REPL, and had to 
> use the server to get the result. But I was able to figure out at the REPL 
> that (f2) and (f4) return something of type `Any`, for some unknown reason. 
> Clearly TR is smart enough to figure out that `resp` is not a Number, but a 
> response, but then when I allow it to return both a type `response` and 
> `Any`, it says that it's return value is `Any`. Why? Every function that can 
> take `Any` can take `response`, and every function that expects response is 
> now going to blow up (as now happens).
>
> At the REPL, I didn't manage to get this behavior, probably because 
> `serve/servlet` has contracts around it's arguments. Thus:
>
> - I pass all the typed racket tests
> - I nonetheless return something of type `Any` (which is really guaranteed to 
> be of type response, and I am already annotating, so this surprises me)
> - When this hits the contract, it complains and tells me that f4 broke its 
> own contract, which seems false, but this may be one of those 'Contract 
> blaming is hard' moments
>
> Long story short: Why do (f2) and (f4) return something of type `Any` rather 
> than `response`? What is the logic for doing this and what use case am I 
> missing where this is a feature (or maybe it's just hard to get right, but 
> this seems vastly easier than other things Typed Racket does).
>
> And yes, I should probably just use typed/web-server/servlet and friends (not 
> sure if everything is covered, but probably) - but I discovered the typed/** 
> modules only while trying to fix this. And the issue will come up with other 
> non-typed modules or when/if I try to created typed versions of some module.
>
> Cheers,
> Marc
>
> --
> 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.
> To view this discussion on the web visit 
> 

[racket-users] Re: Typed Racket: 'Unable to protect opaque value passed as `Any`' with interesting behavior

2019-12-11 Thread Marc Kaufmann
And I forgot: What is the cryptic error message 'any-wrap/c: Unable to 
protect opaque value passed as `Any`' telling me? That response is opaque 
and ... what?

Cheers,
Marc

On Wednesday, December 11, 2019 at 2:31:37 PM UTC+1, Marc Kaufmann wrote:
>
> Hello,
>
> I have one file called `type-test.rkt` with the following (notice that I 
> discovered that there is a typed version of the web-server/http module, 
> which solves another of my issues):
>
> ```
> #lang typed/racket
>
> (require (only-in typed/web-server/http response/xexpr response))
>
> (provide f1 f2 f3 f4)
>
> (: f1 (-> response))
> (define (f1)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f2 (-> (U response Any)))
> (define (f2)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f3 (-> (U response Number)))
> (define (f3)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
>
> (: f4 (-> (U Any response)))
> (define (f4)
>   (define x '(body (h1 "Try it")))
>   (: resp response)
>   (define resp (response/xexpr x))
>   resp)
> ```
>
> Then I have another *untyped* file for a servlet:
>
> ```
> #lang racket
>
> (require "type-test.rkt"
>  web-server/servlet
>  web-server/servlet-env)
>
> (define (start req)
>   (f1)
>   ; (f2)
>   ; (f3)
>   ; (f4)
>   )
>
> (serve/servlet start
>#:servlet-regexp #rx""
>#:launch-browser? #false
>#:port 8080)
> ```
>
> Notice that I am telling all the f* functions that `resp` is of type 
> `response`. Yet, when I run the server with `start` using `f1` through `f4` 
> I get the following results:
>
> (f1): All good
> (f2): Error, see below. Unable to protect opaque value passed as `Any` 
> (f3): All good 
> (f4): Error, see below.
>
> The error is:
>
> ```
>
> f4: broke its own contract
>   any-wrap/c: Unable to protect opaque value passed as `Any`
>   value: #
>   in: the range of
>   (-> Any)
>
> ```
>
> First, I couldn't figure out how to replicate this in the REPL, and had to 
> use the server to get the result. But I was able to figure out at the REPL 
> that (f2) and (f4) return something of type `Any`, for some unknown reason. 
> Clearly TR is smart enough to figure out that `resp` is not a Number, but a 
> response, but then when I allow it to return both a type `response` and 
> `Any`, it says that it's return value is `Any`. Why? Every function that 
> can take `Any` can take `response`, and every function that expects 
> response is now going to blow up (as now happens). 
>
> At the REPL, I didn't manage to get this behavior, probably because 
> `serve/servlet` has contracts around it's arguments. Thus:
>
> - I pass all the typed racket tests
> - I nonetheless return something of type `Any` (which is really guaranteed 
> to be of type response, and I am already annotating, so this surprises me)
> - When this hits the contract, it complains and tells me that f4 broke its 
> own contract, which seems false, but this may be one of those 'Contract 
> blaming is hard' moments
>
> Long story short: Why do (f2) and (f4) return something of type `Any` 
> rather than `response`? What is the logic for doing this and what use case 
> am I missing where this is a feature (or maybe it's just hard to get right, 
> but this seems vastly easier than other things Typed Racket does).
>
> And yes, I should probably just use typed/web-server/servlet and friends 
> (not sure if everything is covered, but probably) - but I discovered the 
> typed/** modules only while trying to fix this. And the issue will come up 
> with other non-typed modules or when/if I try to created typed versions of 
> some module. 
>
> Cheers,
> Marc
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5ea67f27-ddc1-412c-bb8e-dd049172b641%40googlegroups.com.


[racket-users] Typed Racket: 'Unable to protect opaque value passed as `Any`' with interesting behavior

2019-12-11 Thread Marc Kaufmann
Hello,

I have one file called `type-test.rkt` with the following (notice that I 
discovered that there is a typed version of the web-server/http module, 
which solves another of my issues):

```
#lang typed/racket

(require (only-in typed/web-server/http response/xexpr response))

(provide f1 f2 f3 f4)

(: f1 (-> response))
(define (f1)
  (define x '(body (h1 "Try it")))
  (: resp response)
  (define resp (response/xexpr x))
  resp)

(: f2 (-> (U response Any)))
(define (f2)
  (define x '(body (h1 "Try it")))
  (: resp response)
  (define resp (response/xexpr x))
  resp)

(: f3 (-> (U response Number)))
(define (f3)
  (define x '(body (h1 "Try it")))
  (: resp response)
  (define resp (response/xexpr x))
  resp)

(: f4 (-> (U Any response)))
(define (f4)
  (define x '(body (h1 "Try it")))
  (: resp response)
  (define resp (response/xexpr x))
  resp)
```

Then I have another *untyped* file for a servlet:

```
#lang racket

(require "type-test.rkt"
 web-server/servlet
 web-server/servlet-env)

(define (start req)
  (f1)
  ; (f2)
  ; (f3)
  ; (f4)
  )

(serve/servlet start
   #:servlet-regexp #rx""
   #:launch-browser? #false
   #:port 8080)
```

Notice that I am telling all the f* functions that `resp` is of type 
`response`. Yet, when I run the server with `start` using `f1` through `f4` 
I get the following results:

(f1): All good
(f2): Error, see below. Unable to protect opaque value passed as `Any` 
(f3): All good 
(f4): Error, see below.

The error is:

```

f4: broke its own contract
  any-wrap/c: Unable to protect opaque value passed as `Any`
  value: #
  in: the range of
  (-> Any)

```

First, I couldn't figure out how to replicate this in the REPL, and had to 
use the server to get the result. But I was able to figure out at the REPL 
that (f2) and (f4) return something of type `Any`, for some unknown reason. 
Clearly TR is smart enough to figure out that `resp` is not a Number, but a 
response, but then when I allow it to return both a type `response` and 
`Any`, it says that it's return value is `Any`. Why? Every function that 
can take `Any` can take `response`, and every function that expects 
response is now going to blow up (as now happens). 

At the REPL, I didn't manage to get this behavior, probably because 
`serve/servlet` has contracts around it's arguments. Thus:

- I pass all the typed racket tests
- I nonetheless return something of type `Any` (which is really guaranteed 
to be of type response, and I am already annotating, so this surprises me)
- When this hits the contract, it complains and tells me that f4 broke its 
own contract, which seems false, but this may be one of those 'Contract 
blaming is hard' moments

Long story short: Why do (f2) and (f4) return something of type `Any` 
rather than `response`? What is the logic for doing this and what use case 
am I missing where this is a feature (or maybe it's just hard to get right, 
but this seems vastly easier than other things Typed Racket does).

And yes, I should probably just use typed/web-server/servlet and friends 
(not sure if everything is covered, but probably) - but I discovered the 
typed/** modules only while trying to fix this. And the issue will come up 
with other non-typed modules or when/if I try to created typed versions of 
some module. 

Cheers,
Marc

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/777af0ca-0b1f-474a-bd9f-8a9786e2a5c1%40googlegroups.com.