www

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

commit a2b462fc7fe46a71bae829d28eb1ed3b61c6a841
parent 5cf5d1c01b6bbf3dce945f372bf55d7756b843eb
Author: Georges DupΓ©ron <georges.duperon@gmail.com>
Date:   Thu, 29 Jun 2017 20:14:25 +0200

Started working on polymorphic functions

Diffstat:
Mscribblings/state-of-the-art.scrbl | 2++
Mscribblings/tr.scrbl | 101++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 82 insertions(+), 21 deletions(-)

diff --git a/scribblings/state-of-the-art.scrbl b/scribblings/state-of-the-art.scrbl @@ -9,6 +9,8 @@ @title[#:style (with-html5 manual-doc-style) #:version (version-text)]{State of the art} +@htodo{sablecc, treecc, pipelines} + @asection{ @atitle[#:tag "related-type-expander"]{Extending the type system via macros} diff --git a/scribblings/tr.scrbl b/scribblings/tr.scrbl @@ -780,7 +780,7 @@ therefore keep our overview succinct and gloss over most details. (list (if (= i 0) first-sep then-sep) " & " c - (if (= i (sub1 (length the-cases))) "" "\\\\"))) + (if (= i (sub1 (length the-cases))) "" "\\\\\n"))) )))) (define (frac x . y) @list{\frac{@x}{@y}}) @@ -793,7 +793,9 @@ therefore keep our overview succinct and gloss over most details. @list{\mathsf{@x}} @list{\mathsf{@x}\ @y})) (define β„‚βˆž @${\overline{β„‚}}) - (define u𝕋 @${𝕋}) + (define u𝕋 @${𝕋_Ο…}) + (define nu @${Ο…}) + (define uπ•‹βˆ… @${𝕋_βˆ…}) (define (Ο„ x) @${Ο„(\textit{@x})})) @asection{ @@ -850,7 +852,7 @@ therefore keep our overview succinct and gloss over most details. @${𝔽} is the universe of Racket functions. A function @${f ∈ 𝔽} is a partial function from tuples of arguments to tuples of return values. - @$${f : 𝔻ⁿ ↛ 𝔻ⁿ} + @$${𝔽 = 𝔻ⁿ ↛ 𝔻ᡐ @where n,m ∈ β„•} @${β„•} is the set of natural integers. @@ -872,9 +874,24 @@ 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π•‹βˆ… βŠ† 𝒫(𝔻)}. + + @$${ + \begin{gathered} + \textit{tvar} ∈ Ο… β‡’ Ο„(\textit{tvar}) ∈ @u𝕋 \\ + @uπ•‹βˆ… βŠ† 𝒫(𝔻) + \end{gathered} + } + + Values belong to their singleton type. We define a type inhabited by a single - value @${v} with the notation @${Ο„(v) ∈ @u𝕋}, where @u𝕋 is the universe of - types. + value @${v} with the notation @${Ο„(@cat["cat"]{v})}, where @${@cat["cat"]{}} + indicates the ``category'' of the value (whether it is a number, a string, a + function, a boolean…). @$${ @aligned{ @@ -889,7 +906,7 @@ therefore keep our overview succinct and gloss over most details. } } - Values also belong to their wider type, which we note as + These simple values also belong to their wider type, which we note as @; @${Ο„(\textit{Typename})}. @@ -901,16 +918,43 @@ therefore keep our overview succinct and gloss over most details. @cat["sym"]{y} &∈ Ο„(\textit{Symbol}) &βŠ‚ @Ο„{Any} \\ @cat["true"] &∈ Ο„(\textit{Boolean}) &βŠ‚ @Ο„{Any} \\ @cat["false"] &∈ Ο„(\textit{Boolean}) &βŠ‚ @Ο„{Any} \\ - @cat["null"] &∈ Ο„(\textit{Listof\ Nothing}) &βŠ‚ @Ο„{Any} + @cat["null"] & &βŠ‚ @Ο„{Any} \\ + @cat["void"] & &βŠ‚ @Ο„{Any} + } + } + + We give the type of pairs and vector values below: + + @$${ + @aligned{ + @cat["pair"](a, b) &∈ Ο„(\textit{Pairof A B}) &&@textif a ∈ Ο„(A) ∧ b ∈ Ο„(B) \\ + @cat["vec"](a₁, …, aβ‚™) &∈ Ο„(\textit{Vector A₁ … Aβ‚™}) &&@textif aα΅’ ∈ Ο„(Aα΅’) } } + The type @${Ο„(\textit{List}\ A₁\ …\ Aβ‚™)} is a shorthand for describing the + type of linked lists of pairs of fixed length: + @$${ @aligned{ - @cat["pair"](a, b) &∈ Ο„(\textit{Pairof A B}) & @textif a ∈ Ο„(A) ∧ b ∈ Ο„(B) \\ + Ο„(\textit{List}\ A₁\ Aβ‚‚\ …\ Aβ‚™) + &= Ο„(\textit{Pairof}\ A₁\ (List\ Aβ‚‚\ …\ Aβ‚™)) \\ + Ο„(\textit{List}) &= Ο„(Null) } } + More general types exist for linked lists of pairs and vectors of unknown + length: + + @$${ + @aligned{ + @cat["null"] &∈ Ο„(\textit{Listof}\ \textit{A})\ βˆ€\ A \\ + @cat["pair"](a, b) &∈ Ο„(\textit{Listof}\ A) + && @textif a ∈ Ο„(A) ∧ b ∈ Ο„(\textit{Listof}\ A) \\ + @cat["vec"](a₁, …, aβ‚™) &∈ Ο„(\textit{Vectorof}\ A) && @textif aα΅’ ∈ Ο„(A) + } + } + There are a few intermediate types between singleton types for individual numbers and @; @@ -920,9 +964,9 @@ therefore keep our overview succinct and gloss over most details. @$${ @aligned{ - @cat["num"]{c} &∈ Ο„(\textit{Positive-Integer}) & @textif c ∈ β„• ∧ c > 0 \\ - @cat["num"]{c} &∈ Ο„(\textit{Nonnegative-Integer}) & @textif c ∈ β„• ∧ c β‰₯ 0 \\ - @cat["num"]{c} &∈ Ο„(\textit{Nonpositive-Integer}) & @textif c ∈ β„• ∧ c ≀ 0 \\ + @cat["num"]{c} &∈ Ο„(\textit{Positive-Integer}) && @textif c ∈ β„• ∧ c > 0 \\ + @cat["num"]{c} &∈ Ο„(\textit{Nonnegative-Integer}) && @textif c ∈ β„• ∧ c β‰₯ 0 \\ + @cat["num"]{c} &∈ Ο„(\textit{Nonpositive-Integer}) && @textif c ∈ β„• ∧ c ≀ 0 \\ @cat["num"]{0} &∈ Ο„(\textit{Zero}) & \\ @cat["num"]{1} &∈ Ο„(\textit{One}) & } @@ -940,16 +984,35 @@ therefore keep our overview succinct and gloss over most details. &@|quad|@textif vα΅’ ∈ Ο„α΅’ β‡’ (v₁, …, vβ‚™) ∈ dom(f) ∧ f(v₁, …, vβ‚™) ∈ (Ο„'₁, …, Ο„'β‚˜) \\ &@|quad|@where - (o₁, …, oβ‚˜) ∈ (Ο„'₁, …, Ο„'β‚˜) @textif oα΅’ ∈ Ο„'α΅’ + (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 + &@|quad|@textif + βˆ€ \textit{instα΅’} ∈ @u𝕋, vβ±Ό ∈ Οƒ(Ο„β±Ό) + β‡’ (v₁, …, vβ‚™) ∈ dom(f) ∧ f(v₁, …, vβ‚™) ∈ (Οƒ(Ο„'₁), …, Οƒ(Ο„'β‚˜)) \\ + &@|quad|@where Οƒ(Ο„) = Ο„[\textit{tvarα΅’} ↦ \textit{instα΅’} …] } } + where the notation @${Ο„[a₁ ↦ b₁ … aβ‚™ ↦ bβ‚™]} indicates the substitution within + @${Ο„} of all occurrences of @${aα΅’} with the corresponding @${bα΅’}. The + substitutions are performed in parallel. + @todo{if or iff for the function's type above?} @todo{other function types} @todo{dotted function types (variadic with ellipsis)} + @todo{Vectorof, Listof} + + @todo{Intersections} + + @todo{is the notation for tuples of values returned by functions okay?} + @htodo{something else I forgot?} The association with types and values given above naturally yields the @@ -957,6 +1020,8 @@ therefore keep our overview succinct and gloss over most details. @$${ @aligned{ + @Ο„{T} & @tr≀: @Ο„{T}\ βˆ€\ T & \\ + @Ο„{Nothing} & @tr≀: @Ο„{T}\ βˆ€\ T & \\ Ο„(@cat["num"]{n}) & @tr≀: @Ο„{Number} & \\ Ο„(@cat["chr"]{h}) & @tr≀: @Ο„{Char} & \\ Ο„(@cat["str"]{s}) & @tr≀: @Ο„{String} & \\ @@ -964,16 +1029,10 @@ therefore keep our overview succinct and gloss over most details. Ο„(@cat["true"]) & @tr≀: @Ο„{Boolean} & \\ Ο„(@cat["false"]) & @tr≀: @Ο„{Boolean} & \\[1ex] Ο„(A) & @tr≀: Ο„(U\ A\ B\ …) & \\ - Ο„(A₁ … Aβ‚™ β†’ B₁ … Bβ‚˜) & @tr≀: Ο„(A'₁ … A'β‚™ β†’ B'₁ … B'β‚˜) & - @textif A'α΅’ @tr≀: Aα΅’ ∧ Bα΅’ @tr≀: B'α΅’ \\ + Ο„(A₁ … Aβ‚™ β†’ B₁ … Bβ‚˜) & @tr≀: Ο„(A'₁ … A'β‚™ β†’ B'₁ … B'β‚˜) & \\ + & @textif A'α΅’ @tr≀: Aα΅’ ∧ Bα΅’ @tr≀: B'α΅’ & \\ … & @tr≀: … & \\[1ex] - @Ο„{Number} & @tr≀: @Ο„{Any} & \\ - @Ο„{Char} & @tr≀: @Ο„{Any} & \\ - @Ο„{String} & @tr≀: @Ο„{Any} & \\ - @Ο„{Symbol} & @tr≀: @Ο„{Any} & \\ - @Ο„{Boolean} & @tr≀: @Ο„{Any} & \\ - @Ο„{Null} & @tr≀: @Ο„{Any} & \\ - @Ο„{Void} & @tr≀: @Ο„{Any} & + @Ο„{T} & @tr≀: @Ο„{Any}\ βˆ€\ T & } } } \ No newline at end of file