summaryrefslogtreecommitdiffstats
path: root/content/zettel/2a1.md
blob: 8ad44199d968e4b971108f565afc020e8c5bbe65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
+++
title = "Nominal Typing"
author = "Yann Herklotz"
tags = []
categories = []
backlinks = ["2a"]
forwardlinks = ["2ab"]
zettelid = "2a1"
+++

Distinguish types by their names. For example, an `Integer` could be a
`Count` or an `Offset`. Operations based on those types should interact
in a different way. This is different to structured typing ([\#2ab]),
which bases the difference of the type not on the name, but the
structure. For example [^1]:

-   `Count` + `Count` is valid, and should give a `Count`.
-   `Offset` + `Count` is also likely valid, and will give an `Offset`,
    because we can have an `Offset` and some count from a previous
    value, and offset by the amount and the count of that object. The
    new offset is likely to be valid as well.
-   `Count` + `Offset` should probably not be valid, because it is maybe
    expected that it returns a `Count`, which would however not be valid
    (adding a count and an offset does not anything). However, to keep
    associativity, it might make sense to allow this and return an
    `Offset` in that case.
-   `Offset` + `Offset` should not be valid, because this would allow us
    to add offsets which may lead to a new offset that is out of range,
    meaning we could access memory that is not valid.

[^1]: Lelechenko, Andrew. *Haskell for mathematical libraries*. lambda
    DAλS talk (13-14 Feb 2020). Kraków, Poland. \[Online\]
    <https://www.youtube.com/watch?v=qaPdg0mZavM>.

  [\#2ab]: /zettel/2ab