www

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

commit 2ba0cbe492feccd85eafa36a7a145f6faa3b4e98
parent 42c625271230e4d9a71b14f109dce5f792c05624
Author: Georges DupΓ©ron <georges.duperon@gmail.com>
Date:   Tue,  4 Jul 2017 12:27:03 +0200

WIP polymorphic functions

Diffstat:
Mscribblings/tr.scrbl | 50++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/scribblings/tr.scrbl b/scribblings/tr.scrbl @@ -856,8 +856,8 @@ therefore keep our overview succinct and gloss over most details. @list{\mathsf{@x}} @list{\mathsf{@x}\ @y})) (define β„‚βˆž @${\overline{β„‚}}) - (define u𝕋 @${𝕋_Ο…}) - (define nu @${Ο…}) + (define tvarset @${V}) + (define u𝕋 @${𝕋_@tvarset}) (define uπ•‹βˆ… @${𝕋_βˆ…}) (define (Ο„ x) @${Ο„(\textit{@x})})) @@ -937,15 +937,16 @@ therefore keep our overview succinct and gloss over most details. @todo{Value-belongs-to-type relationship:} - We define a universe of types @u𝕋 parameterized by @${Ο… βŠ† 𝕧}, which indicates - the set of free variables which may occur in the type. We note individual - types as @${Ο„(\textit{Type})}. Unless otherwise specified, @${Ο„(\textit{Type}) - ∈ @u𝕋 βˆ€ Ο…}. @todo{The previous sentences are a bit fuzzy.} The universe of - types with no free variables is @${@uπ•‹βˆ… βŠ† \mathcal{P}(𝔻)}. + We define a universe of types @u𝕋 parameterized by @${@tvarset βŠ† 𝕧}, which + indicates the set of free variables which may occur in the type. We note + individual types as @${Ο„(\textit{Type})}, where @${Type} is the name of the + type being considered. Unless otherwise specified, @${Ο„(\textit{Type}) ∈ + @|u𝕋|\ βˆ€ @tvarset}. @todo{The previous sentences are a bit fuzzy.} The + universe of types with no free variables is @${@uπ•‹βˆ… βŠ† \mathcal{P}(𝔻)}. @$${ \begin{gathered} - \textit{tvar} ∈ Ο… β‡’ Ο„(\textit{tvar}) ∈ @u𝕋 \\ + \textit{tvar} ∈ @tvarset β‡’ Ο„(\textit{tvar}) ∈ @u𝕋 \\ @uπ•‹βˆ… βŠ† \mathcal{P}(𝔻) \end{gathered} } @@ -1002,6 +1003,7 @@ therefore keep our overview succinct and gloss over most details. @aligned{ Ο„(\textit{List}\ A\ \overline{B}) &= Ο„(\textit{Pairof}\ A₁\ (List\ \overline{B})) \\ + @where \text{$\overline{B} is a placeholder for any number of types$} Ο„(\textit{List}) &= Ο„(Null) } } @@ -1049,14 +1051,29 @@ therefore keep our overview succinct and gloss over most details. &@|quad|@where (o₁, …, oβ‚˜) ∈ (Ο„'₁, …, Ο„'β‚˜) @textif oα΅’ ∈ Ο„'α΅’\\[1ex] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - &@cat["fun"]{f} ∈ Ο„(βˆ€\ \textit{tvar}\ (τ₁, …, Ο„β‚™ β†’ Ο„'₁, …, Ο„'β‚˜))\\ - &@|quad|@where - Ο„(βˆ€\ \textit{tvar₁}\ …\ \textit{tvarβ‚–}\ (τ₁, …, Ο„β‚™ β†’ Ο„'₁, …, Ο„'β‚˜)) ∈ @u𝕋 \\ - &@|quad|@where υ⁺ = Ο… βˆͺ \{\textit{tvar₁} … \textit{tvarβ‚–}\} \\ - &@|quad|@textif Ο„α΅’, Ο„'β±Ό ∈ 𝕋_{υ⁺} \\ @;TODO: make @u𝕋 take an argument + } + } + + For polymorphic functions, we define a @${\operatorname{freetvars}(t)} + operator, which returns the set of bound variables accessible within a given + type @todo{This is backwards: we did not define well what it means for a bound + variable to be accessible.} + + @$${t ∈ @u𝕋 β‡’ boundvars(t) = @tvarset} + + @todo{We should not have the @${@textif Ο„α΅’, Ο„'β±Ό ∈ 𝕋_{@|tvarset|⁺}} clause + below, instead we should define the notion of well-scopedness of a type.} + + @$${ + @aligned{ + &@cat["fun"]{f} ∈ t = Ο„(βˆ€\ \textit{tvar₁}\ …\ \textit{tvarβ‚–} + \ (τ₁, …, Ο„β‚™ β†’ Ο„'₁, …, Ο„'β‚˜))\\ + &@|quad|@where @tvarset = \operatorname{boundtvars}(t) \\ + &@|quad|@where @|tvarset|⁺ = @tvarset βˆͺ \{\textit{tvar₁} … \textit{tvarβ‚–}\} \\ + &@|quad|@textif Ο„α΅’, Ο„'β±Ό ∈ 𝕋_{@|tvarset|⁺} \\ @;TODO: make @u𝕋 take an argument &@|quad|@textif @aligned[#:valign 'top]{ - βˆ€ \textit{instα΅’} ∈ @u𝕋, vβ±Ό ∈ Οƒ(Ο„β±Ό) βˆ€ i + βˆ€ \textit{instα΅’} ∈ @|u𝕋|\ vβ±Ό ∈ Οƒ(Ο„β±Ό) βˆ€ j β‡’ &(v₁, …, vβ‚™) ∈ dom(f) \\ &∧ f(v₁, …, vβ‚™) ∈ (Οƒ(Ο„'₁), …, Οƒ(Ο„'β‚˜)) } \\ @@ -1080,6 +1097,11 @@ therefore keep our overview succinct and gloss over most details. @todo{is the notation for tuples of values returned by functions okay?} + @todo{A function cannot forge a value of type @racket[A], where @racket[A] is + a polymorphic type variable. It must return an input value with the desired + type (or exit with an error, in which case the function's actual return type + is @racket[Nothing]).} + @htodo{something else I forgot?} The association with types and values given above naturally yields the