www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

adt-row-sub.scrbl (4101B)


      1 #lang scribble/manual
      2 
      3 @require["util.rkt"
      4          "adt-utils.rkt"
      5          (for-label (only-meta-in 0 typed/racket))]
      6 @(use-mathjax)
      7 
      8 @title[#:style (with-html5 manual-doc-style)
      9        #:version (version-text)]{Subtyping (with ρ)}
     10 
     11 Variants which do not involve a row type are nothing more than a syntactic
     12 restriction on a union of types. The variant only allows constructors to be
     13 present in the union, as specified by the type validity rule
     14 @refrule[@textsc{TE-Variant}].
     15 
     16 @$inferrule[-
     17             @=:[@variantτ[@repeated{τ}] @un[@repeated{τ}]]
     18             @${@textsc{S-Variant-Union}}]
     19 
     20 From @refrule[@textsc{S-Variant-Union}], we can derive that the empty variant
     21 is equivalent to the bottom type.
     22 
     23 @$p[@$infertree[(@refrule[@textsc{S-Variant-Union}]
     24                   @refrule[@textsc{S-Bot}]
     25     26                   @refrule[@textsc{S-Eq-Transitive}])
     27     28                 @=:[@variantτ[] ⊥]
     29                 @${@textsc{S-Variant-Empty}}]
     30     @$infertree[(((@${@=:[τ τ′]} ⇒ @refrule[@${@textsc{S-Eq}_1}])
     31                   (@${@=:[τ′ τ″]} ⇒ @refrule[@${@textsc{S-Eq}_1}])
     32     33                   @refrule[@textsc{S-Eq-Transitive}])
     34                  ((@${@=:[τ′ τ″]} ⇒ @refrule[@${@textsc{S-Eq}_2}])
     35                   (@${@=:[τ τ′]} ⇒ @refrule[@${@textsc{S-Eq}_2}])
     36     37                   @refrule[@textsc{S-Eq-Transitive}])
     38     39                  @refrule[@${@textsc{S-Eq}_3}])
     40     41                 @=:[τ τ″]
     42                 @${@textsc{S-Eq-Transitive}}]]
     43 
     44 
     45 @$p[@$inferrule[@${∃ i . @<:[τ @${σᵢ}]}
     46                 @${@<:[τ @variantτ[@repeated{σᵢ}]]}
     47                 @${@textsc{S-VariantSuper}}]
     48 
     49     @$inferrule[@${@repeated[@<:[τᵢ @${σ}]]}
     50                 @${@<:[@variantτ[@repeated{τᵢ}] σ]}
     51                 @${@textsc{S-VariantSub}}]]
     52 
     53 
     54 
     55 
     56 
     57 
     58 
     59 @;{@$inferrule[-
     60                @<:[@ctorτ[@κof[τ]] @ctorTop[τ]]
     61                @${@textsc{S-CtorTop}}]}
     62 
     63 @$inferrule[
     64  @${@<:[τ τ′]}
     65  @<:[@ctorτ[@κof[τ]] @ctorτ[@κof[τ′]]]
     66  @${@textsc{S-Ctor}}]
     67 
     68 @$inferrule[
     69  @${@repeated{@<:[τᵢ τ′ᵢ]}}
     70  @<:[@recordτ[@repeated{@${@|ɐ|ᵢ : τᵢ}}] @recordτ[@repeated{@${@|ɐ|ᵢ : τ'ᵢ}}]]
     71  @${@textsc{S-Record}}]
     72 
     73 @$inferrule[
     74  @${@repeated{@<:[τⱼ τ′ⱼ]}}
     75  @<:[@recordτ[@repeated{@${@|ɐ|ⱼ : τⱼ}}]
     76      @recordτ[@|ρf| @repeatset{-@|ɐ|ᵢ} @repeatset{+@|ɐ|ⱼ:τ'ⱼ}]]
     77  @${@textsc{S-RecordF}}]
     78 
     79 @$inferrule[@${@repeated{@<:[τₖ τ′ₖ]}}
     80             @<:[@recordτ[@|ρf|
     81                          @repeatset{-@|ɐ|ᵢ}
     82                          @repeatset{-@|ɐ|ⱼ}
     83                          @repeatset{+@|ɐ|ₖ:τₖ}
     84                          @repeatset{+@|ɐ|ₗ:τₗ}]
     85                 @recordτ[@|ρf|
     86                          @repeatset{-@|ɐ|ᵢ}
     87                          @repeatset{+@|ɐ|ₖ:τ'ₖ}]]
     88             #:wide #t
     89             @${@textsc{S-FRecordF}}]
     90 
     91 @$inferrule[@${@<:[@${τ[@repeated{@|ρf|ᵢ ↦ @|ρf|′ᵢ}]} σ]}
     92             @${@<:[@∀f[(@repeated{@|ρf|ᵢ}) τ]
     93                    @∀f[(@repeated{@|ρf|′ᵢ}) σ]]}
     94             @${@textsc{S-PolyF-}α@textsc{-Equiv}}]
     95 
     96 @$inferrule[@${@<:[@${τ[@repeated{@|ρc|ᵢ ↦ @|ρc|′ᵢ}]} σ]}
     97             @${@<:[@∀c[(@repeated{@|ρc|ᵢ}) τ]
     98                    @∀c[(@repeated{@|ρc|′ᵢ}) σ]]}
     99             @${@textsc{S-PolyC-}α@textsc{-Equiv}}]
    100 
    101 @; TODO: can these rules be used to combine a record type and a record*?
    102 @; predicate to make sure some fields are absent, without checking anything
    103 @; for the other fields?
    104 
    105 @; TODO: instantiation rules. ∀ rules. Etc.
    106 
    107 @;{
    108  Permutation of the fields of a record type produces an equivalent type:
    109 
    110  @$${
    111   @$inferrule[
    112  @${\phantom{x}}
    113  @<:[@recordτ[@repeated{@${@|ɐ|ᵢ : τᵢ}} @repeated{@${@|ɐ|ⱼ : τⱼ}}]
    114      @recordτ[@repeated{@${@|ɐ|ⱼ : τⱼ}} @repeated{@${@|ɐ|ᵢ : τᵢ}}]]
    115  @${@textsc{S-Record-Permuation}}
    116  ]
    117  }
    118 }
    119 
    120 @todo{propagate our types up/down unions like the primitive ones (I think
    121  Typed Racket does not do this everywhere it “should”).}