printing structures in typed Racket

19 views
Skip to first unread message

Hendrik Boom

unread,
May 15, 2020, 8:00:36 AM5/15/20
to Racket Users
How does one provide a method to print strutures in typed Racket?

(struct parameter

([type : XML] [name : Symbol] [len : (Option String)] [const? : Boolean] [stars : Integer])
#:methods gen:custom-write [(define write-proc parameter-print)]
)

seems not to work. But something like this did work in untyped Racket.
Is there some other way to do this?

-- hendrik

Sam Tobin-Hochstadt

unread,
May 15, 2020, 10:07:48 AM5/15/20
to Racket Users
Generics are not supported yet; you need to use structure type
properties, like this:

#lang typed/racket/base

(: parameter-print : Any Output-Port Any -> Any)
(define (parameter-print v p b) (fprintf p "hi\n"))

(struct parameter
([type : String] [name : Symbol] [len : (Option String)] [const? :
Boolean] [stars : Integer])
#:property prop:custom-write parameter-print)
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200515120026.ski2o43crgtnsnr3%40topoi.pooq.com.

Hendrik Boom

unread,
May 15, 2020, 10:33:56 AM5/15/20
to Racket Users
On Fri, May 15, 2020 at 10:07:31AM -0400, Sam Tobin-Hochstadt wrote:
> Generics are not supported yet; you need to use structure type
> properties, like this:
>
> #lang typed/racket/base
>
> (: parameter-print : Any Output-Port Any -> Any)
> (define (parameter-print v p b) (fprintf p "hi\n"))
>
> (struct parameter
> ([type : String] [name : Symbol] [len : (Option String)] [const? :
> Boolean] [stars : Integer])
> #:property prop:custom-write parameter-print)

Thank you. That worked.

But according to section 2.5 of the typed Racket reference, #:property
is not one of the allowed options in struct.

Perhaps the documentation needs to be updated/

-- hendrik

>
> On Fri, May 15, 2020 at 8:00 AM Hendrik Boom <hen...@topoi.pooq.com> wrote:
> >
> > How does one provide a method to print strutures in typed Racket?
> >
> > (struct parameter
> >
> > ([type : XML] [name : Symbol] [len : (Option String)] [const? : Boolean] [stars : Integer])
> > #:methods gen:custom-write [(define write-proc parameter-print)]
> > )
> >
> > seems not to work. But something like this did work in untyped Racket.
> > Is there some other way to do this?
> >
> > -- hendrik
> >
> > --
> > 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...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200515120026.ski2o43crgtnsnr3%40topoi.pooq.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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BZFMR0evj%2B%3DcoeQaaQ602f7rGj76HtNc7N3bswipH7aEg%40mail.gmail.com.

Sam Tobin-Hochstadt

unread,
May 15, 2020, 10:58:51 AM5/15/20
to Racket Users
I've updated the docs.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200515143347.ceg34vkaelx6sdu2%40topoi.pooq.com.
Reply all
Reply to author
Forward
0 new messages