Merge pull request 'write initial type signature notation proposal' (#5) from schrottkatze/iowo:type-notation into main
Reviewed-on: #5 Reviewed-by: multisn8 <forgejo-schrottkatze@multisamplednight.com>
This commit is contained in:
commit
70256a7bfc
1 changed files with 38 additions and 0 deletions
38
docs/design/type-notation.typ
Normal file
38
docs/design/type-notation.typ
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#import "../template.typ": conf
|
||||||
|
#show: conf
|
||||||
|
|
||||||
|
= Type/signature notation
|
||||||
|
|
||||||
|
Operator signature that takes two unnamed arbitrary numbers of the same type and returns another:
|
||||||
|
|
||||||
|
```iowo
|
||||||
|
Op<T: Num> [ T T ] -> T
|
||||||
|
```
|
||||||
|
|
||||||
|
Operator signature that takes any color and any number type, and returns a color again:
|
||||||
|
```iowo
|
||||||
|
Op<C: Color, M: Num> [ C M ] -> C
|
||||||
|
```
|
||||||
|
|
||||||
|
Operator that takes a 32 bit signed integer and returns another:
|
||||||
|
|
||||||
|
```iowo
|
||||||
|
Op i32 -> i32
|
||||||
|
```
|
||||||
|
|
||||||
|
Operator that does the same with a generic arbitrary number type:
|
||||||
|
|
||||||
|
```iowo
|
||||||
|
Op<T: Num> T -> T
|
||||||
|
```
|
||||||
|
|
||||||
|
One dimensional list of 32 bit signed integers:
|
||||||
|
|
||||||
|
```iowo
|
||||||
|
[i32]
|
||||||
|
```
|
||||||
|
|
||||||
|
Due to inference, you'll also be able to use that in some mathematical operations with integers:
|
||||||
|
|
||||||
|
`[i32] + i32` is a valid operation, for example (of course, you can't add types.) But that wouldn't add the second one to the list, but rather add the single i32 to all values in the left hand side list). That would also work with more dimensional arrays and dynamic streams like videos.
|
||||||
|
|
Loading…
Reference in a new issue