-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass on polymorphic contracts and user types documentation
- Loading branch information
Showing
4 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Polymorphic User Types | ||
====================== | ||
|
||
Kind 2 supports **polymorphic user types**, | ||
which are user-defined types that contain type parameters. | ||
An example is a polymorphic user-defined ``Pair`` type, | ||
shown below, declared as ``type Pair<<T; U>> = [T, U];``. | ||
|
||
A polymorphic user-defined type ``T`` is instantiated with ``T<<...>>`` | ||
syntax (analogous to polymorphic nodes and node calls) | ||
as in the following examples. | ||
|
||
.. code-block:: none | ||
type Pair<<T; U>> = [T, U]; | ||
node SwapIntBool(x: Pair<<int; bool>>) returns (y: Pair <<bool; int>>) | ||
let | ||
y = {x.%1, x.%0}; | ||
tel | ||
node SwapGeneric<<T; U>>(x: Pair<<T; U>>) returns (y: Pair <<U; T>>) | ||
let | ||
y = {x.%1, x.%0}; | ||
tel | ||
In other words, ``Pair`` (or any other user-defined polymorphic type) can | ||
be viewed as as a ``type constructor`` which takes types as inputs | ||
and returns a type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters