Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: typed racket interface #52

Open
joha2 opened this issue May 10, 2022 · 1 comment
Open

Feature request: typed racket interface #52

joha2 opened this issue May 10, 2022 · 1 comment

Comments

@joha2
Copy link

joha2 commented May 10, 2022

First of all: this is a very nice package! Keep up the good work!

I'd like to use gregor in a project together with typed racket. I was able to write a (require/typed ...) interface to some of its most important functions by using opaque types and the predicates:

(require gregor)
(require gregor/period)

(require/typed gregor
               [#:opaque Date date?]
               [#:opaque DateTime datetime?]
               [#:opaque Moment moment?]
               [date (case->
                      [Integer -> Date]
                      [Integer Integer -> Date]
                      [Integer Integer Integer -> Date])]
               [date->iso8601 (-> Date String)]
...)

My problem now is, that I would like to work with period?s, too. But here the opaque type trick

(require/typed gregor/period
               [#:opaque Period period?])
(define-type DateArithmeticProvider (U DateProvider Period))
(require/typed gregor
               [+days (-> DateArithmeticProvider Integer DateArithmeticProvider)])

does not work, since using (+days (date 2222 11 1) 2) throws warnings which may in the future become errors:

period?: contract violation
  any-wrap/c: Unable to protect opaque value passed as `Any`
  value: #<date 2222-11-03>
  This warning will become an error in a future release.
  in: the 1st argument of
      a part of the or/c of
      (or/c
       struct-predicate-procedure?/c
       (-> Any boolean?))
  contract from: (interface for period?)
  blaming: <pkgs>/test/gregor_interface.rkt
   (assuming the contract is correct)
  at: <pkgs>/test/gregor_interface.rkt:52:32
#<date 2222-11-03>

where the source position gregor_interface.rkt:52:32 corresponds to the opaque type definition of Period.

I have to admit, the I am a total n00b in racket, which means I have no real understanding of the deeper mechanisms of the type system of typed/racket and its interaction with contracts.

My two questions on this issue are:

  • Is there already a typed/racket interface to gregor which I missed?
  • Is there a better or another possibility to write such a typed/racket interface to gregor (in particular for using period?)?

Thank you!

@joha2
Copy link
Author

joha2 commented Dec 12, 2022

Since I observed new activity in another issue, I thought I could revive this issue, too. Is there any news or comment on this matter @97jaz 😸? Sorry for bothering you 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant