Skip to content

Commit

Permalink
Merge pull request #4882 from jpetkau/patch-1
Browse files Browse the repository at this point in the history
Document alternative type declaration syntax
  • Loading branch information
jfdm committed Aug 28, 2020
2 parents 4b96183 + 282de12 commit f904fbc
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions docs/tutorial/typesfuns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,27 @@ follows:
The above declarations are taken from the standard library. Unary
natural numbers can be either zero (``Z``), or the successor of
another natural number (``S k``). Lists can either be empty (``Nil``)
or a value added to the front of another list (``x :: xs``). In the
declaration for ``List``, we used an infix operator ``::``. New
operators such as this can be added using a fixity declaration, as
follows:
or a value added to the front of another list (``x :: xs``).

Data types may also be declared by giving just the *types* of the
constructors. These definitions are equivalent to those above:

.. code-block:: idris
data Nat : Type where
Z : Nat
S : Nat -> Nat
data List : Type -> Type where
Nil : List a
(::) : a -> List a -> List a
This syntax is more verbose, but more flexible, and is used for
types that can't be described with the simpler syntax.

In the declaration for ``List``, we used an infix operator ``::``.
New operators such as this can be added using a fixity declaration,
as follows:

::

Expand Down

0 comments on commit f904fbc

Please sign in to comment.