'Racket: can we import struct only from other module?

file lib.rkt:

#lang typed/racket
(provide 
    distance
    pt-to-string
    (struct-out pt))

(struct pt ([x : Real] [y : Real]))

(: pt-to-string (-> pt String))
(define (pt-to-string p) (string-append "struct pt: x=" (number->string (pt-x p)) ", y=" (number->string (pt-y p)) "."))

(: distance (-> pt pt Real))
(define (distance p1 p2)
  (sqrt (+ (sqr (- (pt-x p2) (pt-x p1)))
           (sqr (- (pt-y p2) (pt-y p1))))))

file main.rkt:

#lang typed/racket
(require
  ; import struct pt only, include pt, pt-x and pt-y
  (only-in "./lib.rkt" pt pt-x pt-y))

(define p (pt -1 1))
(displayln (pt-x p))

I want to import struct pt only ,which include pt pt-x and pt-y, but not import all other helper function such as distance and pt-to-string.

Is there anything corresponding to (provide (struct-out ...)) ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source