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:
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