[racket-users] Puzzled by Typed Racket

2016-03-03 Thread Antonio Menezes Leitao
Hi,

Here is a MWE for something that is puzzling me. In file testtyped.rkt, I have

#lang typed/racket

(provide foobar)

(struct (T) foo
  ([x : (T -> T)]))

(define (foobar [a : Boolean])
  (if a
  (foo (lambda ([x : Number]) x))
  (foo (lambda ([x : String]) x

In the REPL, I can test this file and it works fine:

Language: typed/racket; memory limit: 2048 MB.
> foobar
- : (-> Boolean (U (foo Number) (foo String)))
#
> (foobar #t)
- : (U (foo Number) (foo String))
#
> (foobar #f)
- : (U (foo Number) (foo String))
#


However, using it from non-typed racket causes an error.  If, in file
test.rkt we have:

#lang racket
(require "testtyped.rkt")

;;Note that this is _not_ typed/racket

Then the same example stops working:

> (foobar #t)
. . foobar: broke its own contract
  two of the clauses in the or/c might both match: (struct/c foo (->
Number any)) and (struct/c foo (-> String any))
  produced: #
  in: the range of
  (->
   (or/c #f #t)
   (or/c
(struct/c foo (-> Number any))
(struct/c foo (-> String any
  contract from:
  C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt
  blaming: C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt
   (assuming the contract is correct)
  at: C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt:3.9

I know that Typed Racket has limitations in the generation of
contracts. Is this one of them? Is there a workaround?

Best,
António.

-- 
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] Typed Racket and struct

2015-11-20 Thread Antonio Menezes Leitao
Hi,

On Thu, Nov 19, 2015 at 8:29 PM, Asumu Takikawa <as...@ccs.neu.edu> wrote:

> On 2015-11-19 09:11:08 +, Antonio Menezes Leitao wrote:
> >So, my questions are:
> >1. Are there any plans to support #:constructor-name in Typed Racket?
>
> I haven't tried to implement support for it, but I can't think of anything
> off
> the top of my head that would make it difficult. I suspect we just haven't
> gotten around to it.
>
> Maybe we can support it for (add1 v6.3).
>
>
That would be great!

I don't mind testing it on a snapshot build.

Best,
António.

-- 
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] Typed Racket and struct

2015-11-20 Thread Antonio Menezes Leitao
Hi,

On Fri, Nov 20, 2015 at 1:59 AM, WarGrey Gyoudmon Ju <juzhenli...@gmail.com>
wrote:

>
>
> On Fri, Nov 20, 2015 at 3:27 AM, Antonio Menezes Leitao <
> antonio.menezes.lei...@ist.utl.pt> wrote:
>
>> Hi,
>>
>> On Thu, Nov 19, 2015 at 11:36 AM, WarGrey Gyoudmon Ju <
>> juzhenli...@gmail.com> wrote:
>>
>>> 1. define structs in untyped racket;
>>> 2. (require/typed/provide) it with #:constructor-name option.
>>>
>>>
>> Thanks for the suggestion.
>>
>> Meanwhile, I thought about a different approach. Here is one example:
>>
>> (module test typed/racket
>>   (struct foo
>> ([a : Real]
>>  [b : Integer]))
>>   (provide (except-out (struct-out foo) foo)
>>(rename-out [foo new-foo])))
>>
>> (require 'test)
>>
>> (define f (new-foo 1.0 2))
>>
>> (foo-a f)
>>
>> (foo-b f)
>>
>> Can you (or someone else) comment on the advantages of these two
>> approaches?
>>
>
> Generally speaking, Racket Struct is not only a compact data collection
> (like a vector with fields accessors, benefits both compiler and human
> readers), Struct itself also has their own properties and methods to define
> generic interfaces which is widely known in Class-based System (ignoring
> that Racket Class-based System is also implemented in terms of Struct, they
> are different things but have same effects).
>
> Currently, Typed Racket only treats Struct as the compact data collection,
> therefore, if you want to take full advantages of Struct, defining it in
> untyped module than requiring it in typed module is the only choice, but
> not vice versa.
>

That's a good point. Thanks.


> I never tried your approach in practice, and you have already known the
> side effects. Nonetheless, if you don't like the untyped way. How about
> just defining one more function to make its instance? In thi way, you also
> have a more flexible guard procedure (see #:guard option). Besides I just
> cannot understand the design of #:auto and #:auto-value options, it's so
> weird that almost makes nonsense.
>
>
>>
>> Finally, can we define syntax to wrap both the module and the require? Is
>> it possible for a macro to expand into such combination of forms? My quick
>> experiments didn't produce the results I was expecting.
>>
>
> I found it impossible too.
>
>
>>
>> Best,
>> António.
>>
>
> --
> 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] Typed Racket and struct

2015-11-19 Thread Antonio Menezes Leitao
Hi,

I've been using Typed Racket in the last few months and it has been an
interesting experience.

However, there are a few helpful features of "normal" Racket that are not
yet available in Typed Racket.

One of them is the ability to use #:constructor-name in struct type
definitions.

I used rename-out as a replacement but it is not the same thing and it has
other annoying effects.

So, my questions are:

1. Are there any plans to support #:constructor-name in Typed Racket?

2. Which techniques do you recommend to circumvent that lack
of #:constructor-name ?

Best regards,
António.

-- 
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] Typed Racket and struct

2015-11-19 Thread Antonio Menezes Leitao
Hi,

On Thu, Nov 19, 2015 at 11:36 AM, WarGrey Gyoudmon Ju <juzhenli...@gmail.com
> wrote:

> 1. define structs in untyped racket;
> 2. (require/typed/provide) it with #:constructor-name option.
>
>
Thanks for the suggestion.

Meanwhile, I thought about a different approach. Here is one example:

(module test typed/racket
  (struct foo
([a : Real]
 [b : Integer]))
  (provide (except-out (struct-out foo) foo)
   (rename-out [foo new-foo])))

(require 'test)

(define f (new-foo 1.0 2))

(foo-a f)

(foo-b f)

Can you (or someone else) comment on the advantages of these two approaches?

Finally, can we define syntax to wrap both the module and the require? Is
it possible for a macro to expand into such combination of forms? My quick
experiments didn't produce the results I was expecting.

Best,
António.



> On Thu, Nov 19, 2015 at 5:11 PM, Antonio Menezes Leitao <
> antonio.menezes.lei...@ist.utl.pt> wrote:
>
>> Hi,
>>
>> I've been using Typed Racket in the last few months and it has been an
>> interesting experience.
>>
>> However, there are a few helpful features of "normal" Racket that are not
>> yet available in Typed Racket.
>>
>> One of them is the ability to use #:constructor-name in struct type
>> definitions.
>>
>> I used rename-out as a replacement but it is not the same thing and it
>> has other annoying effects.
>>
>> So, my questions are:
>>
>> 1. Are there any plans to support #:constructor-name in Typed Racket?
>>
>> 2. Which techniques do you recommend to circumvent that lack
>> of #:constructor-name ?
>>
>> Best regards,
>> António.
>>
>> --
>> 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.
>

-- 
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.