all repos — min @ 70063984985226895c35ae7b6b9da2cc47c66864

A small but practical concatenative programming language.

Added docs on type aliases.
h3rald h3rald@h3rald.com
Sat, 06 Feb 2021 08:15:29 +0000
commit

70063984985226895c35ae7b6b9da2cc47c66864

parent

cc77a4c122fb4b88255c4e8b51d4786a91da2d61

4 files changed, 63 insertions(+), 19 deletions(-)

jump to
M minpkg/core/utils.nimminpkg/core/utils.nim

@@ -189,7 +189,6 @@ andr = i.validate(value, t, generics)

if neg: andr = not andr if not andr: - echo t if neg: vTypes[c] = t else:
M next-release.mdnext-release.md

@@ -75,3 +75,25 @@ 4 test ; error

6 test ; true 11 test ; true ``` + +### Type aliases + +You can definenow *type aliases* using the {#link-operator||lang||typealias#} operator. Mmmm + +For example, you can create an alias of part of the type expression used in the previous example, like this: + +``` +'tenminus&fiveplus 'five-to-ten typealias + +(symbol test + (!even|five-to-ten :n ==> bool :o) + ( + true @o + ) +) :: +``` + +Note that: +* Type aliases be used to create an alias for any type expression. +* Aliased type expressions can contain standard {{m}} types, dictionary types, type classes, and even other type aliases. +* The {#link-operator||lang||typealias#} operator actually creates lexically-scoped, `typealias:`-prefixed symbols that can be sealed, unsealed, and deleted exactly like other symbols.
M site/contents/learn-operators.mdsite/contents/learn-operators.md

@@ -197,7 +197,7 @@ * Lambdas must be captured using the `^` sigil in signatures and bound using {#link-operator||lang||lambda-bind#} in the operator body.

* Lambdas cannot be captured in input values (they have already been pushed on the stack). * Requiring a lambda as an output value effectively bypasses stack pollution checks. While this can be useful at times, use with caution! -### Type Expressions +### Type expressions When specifying types in operator signatures or through the {#link-operator||lang||expect#} operator, you can specify a logical expression containing types and type classes joined with one kf the following operators:

@@ -243,6 +243,28 @@ 4 test ; error

6 test ; true 11 test ; true ``` + +### Type aliases + +As you can see, type expressions can quickly become quite long and complex. To avoid this, you can define *type aliases* using the {#link-operator||lang||typealias#} operator. + +For example, you can create an alias of part of the type expression used in the previous example, like this: + +``` +'tenminus&fiveplus 'five-to-ten typealias + +(symbol test + (!even|five-to-ten :n ==> bool :o) + ( + true @o + ) +) :: +``` + +Note that: +* Type aliases be used to create an alias for any type expression. +* Aliased type expressions can contain standard {{m}} types, dictionary types, type classes, and even other type aliases. +* The {#link-operator||lang||typealias#} operator actually creates lexically-scoped, `typealias:`-prefixed symbols that can be sealed, unsealed, and deleted exactly like other symbols. ### Generics
M tests/lang.mintests/lang.min

@@ -311,30 +311,31 @@ ) ::

("a" "b" add "ab" ==) *test/assert ((1 2 3) (4 5) add (1 2 3 4 5) ==) *test/assert - ( - (typeclass fiveplus + + (typeclass fiveplus (int :n ==> bool :o) ( n 5 > @o ) - ) :: + ) :: - (typeclass tenminus - (int :n ==> bool :o) - ( - n 10 < @o - ) - ) :: + (typeclass tenminus + (int :n ==> bool :o) + ( + n 10 < @o + ) + ) :: - (typeclass even - (int :n ==> bool :o) - ( - n 2 mod 0 == @o - ) - ) :: - + (typeclass even + (int :n ==> bool :o) + ( + n 2 mod 0 == @o + ) + ) :: + ( + 'tenminus&fiveplus 'five-to-ten typealias (symbol test - (!even|tenminus&fiveplus :n ==> bool :o) + (!even|five-to-ten :n ==> bool :o) ( true @o )