PasteRack.org
Paste # 9039
2015-01-29 13:43:41

Fork as a new paste.

Paste viewed 24 times.


Embed:

  1. #lang typed/racket/base
  2.  
  3. ;;; Parametric import styles
  4.  
  5. ;; style 1: separate form
  6. ;; *************************************
  7. ;; This is sort of nice in the sense that it would likely be extremely easy to
  8. ;; implement. It also makes it very clear what's happening. The downside is that
  9. ;; introducing an entirely new require form is a real pain from a lot of other
  10. ;; perspectives. Do we need require/typed/parametric/provide? That's a mouthful.
  11. ;; Plus, it's not composable, so we'd need to port all the changes from
  12. ;; require/typed to this form manually.
  13.  
  14. #;(require/typed/parametric
  15.    (A)
  16.    [#:opaque (Posn A) posn?]
  17.    [make-posn (A A -> (Posn A))]
  18.    [posn-x ((Posn A) -> A)]
  19.    [posn-y ((Posn A) -> A)])
  20.  
  21.  
  22. ;; style 2: nested clause
  23. ;; *************************************
  24. ;; This maintains most of the simplicity from the first example while reducing
  25. ;; the downsides. This is a good compromise if a nicer style isn't easy to
  26. ;; implement.
  27.  
  28. #;(require/typed
  29.    [#:parametric
  30.     (A)
  31.     [#:opaque (Posn A) posn?]
  32.     [make-posn (A A -> (Posn A))]
  33.     [posn-x ((Posn A) -> A)]
  34.     [posn-y ((Posn A) -> A)]])
  35.  
  36.  
  37. ;; style 3: internal type definition
  38. ;; *************************************
  39. ;; This is the parametric style provided by contract-out. This is especially
  40. ;; nice since it doesn't introduce any addition nesting levels and it's fairly
  41. ;; transparent to a user. The only question is how easy it would be to create a
  42. ;; local parametric type definition and then use that in the generated
  43. ;; contracts. This also maintains consistency with other areas of TR.
  44.  
  45. #;(require/typed
  46.    #:forall [A] ; or #:∀ [A]
  47.    [#:opaque (Posn A) posn?]
  48.    [make-posn (A A -> (Posn A))]
  49.    [posn-x ((Posn A) -> A)]
  50.    [posn-y ((Posn A) -> A)])

=>