[racket-users] Re: Need help porting a library to Typed Racket

2017-08-07 Thread hiphish
Thank you for your response. Right now I cannot implement it because either 
Racket or my package manager (or both) keeps breaking itself, but I will keep 
in mind what you said.

-- 
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: Need help porting a library to Typed Racket

2017-08-06 Thread Ray Racine
And back from the beach ...

So I did observe the opaque error when attempting to run:
 raco test test/unpack/extension.rkt

"A" way to clear that error is specify for TR what the procedure does
actually return as opposed to punting to Any.  unpack really doesn't return
Any-thing.  It returns a fixed, enumerable set of types.  Worth leveraging
the knowledge.

Type Racket inference was strong enough generously report errors until the
following was realized.:

(define-type MsgPack-Type (U Integer HashTableTop VectorTop String Real
Bytes EOF Void Boolean ext))

(: unpack (-> Input-Port MsgPack-Type))
(define (unpack ...) ...)

as opposed to (: unpack (-> Input-Port Any))

With that change:
$ raco test test/unpack/extension.rkt
raco test: (submod "test/unpack/extension.rkt" test)
OK, passed 100 tests.
OK, passed 100 tests.
OK, passed 100 tests.
OK, passed 100 tests.
OK, passed 100 tests.
OK, passed 100 tests.
OK, passed 100 tests.
7 tests passed

Note the EOF value is still being returned by the `unpack` procedure.  You
may or may not handle that case internal to the procedure.  i.e. (error
'Unrecoverable-EOF-Error ... ) or whatever.

Which is another point you raised which is that Typed Racket makes you
explicitly deal with fact that many IO routines can and will return EOFs.
Think of these as common bugs lurking in Untyped Racket code and that Typed
Racket is requiring to be treated with come error flow path that addresses
these error situations.

In IO-land stuff happens ... so given an unexpected, unrecoverable error
such as a socket has gone bad or similar and you get a EOF in many cases
raising an exception does make sense.  Sometimes something like an Either
or Option type style is more appropriate.  Sometimes it is just personal
preference.   IO is just landmines everywhere ...


Final thought.  The use of upper cased types is fairly routine in Typed
Racket.

Might consider.

 ;; Ext vs ext as struct's type and ctor name
(struct Ext ([type : Integer] [data : Bytes]))

giving
(define-type MsgPack-Type (U Integer HashTableTop VectorTop String Real
Bytes EOF Void Boolean Ext))





On Sun, Aug 6, 2017 at 4:00 PM, Ray Racine  wrote:

> Very much hurried and will look at it later ...
>
> 1. Don't use (file "xyz.rkt") just change it all to "xyz.rkt".  i.e. drop
> the (file ).
> 2. The dir MsgPack.rkt uses invalid chars (assume the '.') so change it to
> say "msgpack/"
> 3. See 1.7.3 Linking and Developing New Packages in Racket Docs.
>  Run '$ raco pkg install'  which will make your collection visible,
> including for tests.
>  e.g.
>  % raco test test/pack/binary.rkt
>  raco test: (submod "test/pack/binary.rkt" test)
> OK, passed 100 tests.
> OK, passed 100 tests.
> 2 tests passed
> 4.  With regard to the ext #:transparent and the
>   unpack: broke its own contract
>   any-wrap/c: Unable to protect opaque value passed as `Any`
>  value: #
>  I have hit this landmine before but as I recall usually on a
> (require/typed [#:opaque ...]) situation.
>  Try googling the error.  I recall some suggestion on a
> define-refined-subtype of the opaque structure or some such to allow the
> contract to wrap.   I'll definitely look at it tonight if someone else
> doesn't offer up a solution.
>
>
>
> On Sun, Aug 6, 2017 at 12:35 PM,  wrote:
>
>> *bump* I hope bumping is not frowned upon here. I just need to sort this
>> one last issue out
>>
>> --
>> 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: Need help porting a library to Typed Racket

2017-08-06 Thread Ray Racine
Very much hurried and will look at it later ...

1. Don't use (file "xyz.rkt") just change it all to "xyz.rkt".  i.e. drop
the (file ).
2. The dir MsgPack.rkt uses invalid chars (assume the '.') so change it to
say "msgpack/"
3. See 1.7.3 Linking and Developing New Packages in Racket Docs.
 Run '$ raco pkg install'  which will make your collection visible,
including for tests.
 e.g.
 % raco test test/pack/binary.rkt
 raco test: (submod "test/pack/binary.rkt" test)
OK, passed 100 tests.
OK, passed 100 tests.
2 tests passed
4.  With regard to the ext #:transparent and the
  unpack: broke its own contract
  any-wrap/c: Unable to protect opaque value passed as `Any`
 value: #
 I have hit this landmine before but as I recall usually on a
(require/typed [#:opaque ...]) situation.
 Try googling the error.  I recall some suggestion on a
define-refined-subtype of the opaque structure or some such to allow the
contract to wrap.   I'll definitely look at it tonight if someone else
doesn't offer up a solution.



On Sun, Aug 6, 2017 at 12:35 PM,  wrote:

> *bump* I hope bumping is not frowned upon here. I just need to sort this
> one last issue out
>
> --
> 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] Re: Need help porting a library to Typed Racket

2017-08-06 Thread hiphish
*bump* I hope bumping is not frowned upon here. I just need to sort this one 
last issue out 

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