on master help sign in
Merge pull request #2543 from jfdm/record-docs
60f0cb5Jan de Muijnck-Hughes
.gitignore+2
@@ -1,3 +1,5 @@
1+\#*
2+.\#*
1dist
3dist
2cabal-dev/
4cabal-dev/
3.cabal-sandbox
5.cabal-sandbox
docs/effects/conclusions.rst+10−10
@@ -13,17 +13,17 @@ paper [1]_.
13Some libraries and programs which use ``Effects`` can be found in the
13Some libraries and programs which use ``Effects`` can be found in the
14following places:
14following places:
15
15
16−- http://github.com/edwinb/SDL-idris — some bindings for the SDL media
16+- https://github.com/edwinb/SDL-idris — some bindings for the SDL media
17 library, supporting graphics in particular.
17 library, supporting graphics in particular.
18
18
19−- http://github.com/edwinb/idris-demos — various demonstration
19+- https://github.com/edwinb/idris-demos — various demonstration
20 programs, including several examples from this tutorial, and a “Space
20 programs, including several examples from this tutorial, and a “Space
21 Invaders” game.
21 Invaders” game.
22
22
23- https://github.com/SimonJF/IdrisNet2 — networking and socket
23- https://github.com/SimonJF/IdrisNet2 — networking and socket
24 libraries.
24 libraries.
25
25
26−- http://github.com/edwinb/Protocols — a high level communication
26+- https://github.com/edwinb/Protocols — a high level communication
27 protocol description language.
27 protocol description language.
28
28
29The inspiration for the ``Effects`` library was Bauer and Pretnar’s
29The inspiration for the ``Effects`` library was Bauer and Pretnar’s
@@ -37,32 +37,32 @@ foundations are also well-studied see [5]_, [6]_, [7]_, [8]_.
37.. [1] Edwin Brady. 2013. Programming and reasoning with algebraic
37.. [1] Edwin Brady. 2013. Programming and reasoning with algebraic
38 effects and dependent types. SIGPLAN Not. 48, 9 (September
38 effects and dependent types. SIGPLAN Not. 48, 9 (September
39 2013), 133-144. DOI=10.1145/2544174.2500581
39 2013), 133-144. DOI=10.1145/2544174.2500581
40− http://doi.acm.org/10.1145/2544174.2500581
40+ https://dl.acm.org/citation.cfm?doid=2544174.2500581
41
41
42.. [2] Andrej Bauer, Matija Pretnar, Programming with algebraic
42.. [2] Andrej Bauer, Matija Pretnar, Programming with algebraic
43 effects and handlers, Journal of Logical and Algebraic Methods
43 effects and handlers, Journal of Logical and Algebraic Methods
44 in Programming, Volume 84, Issue 1, January 2015, Pages
44 in Programming, Volume 84, Issue 1, January 2015, Pages
45 108-123, ISSN 2352-2208,
45 108-123, ISSN 2352-2208,
46− http://dx.doi.org/10.1016/j.jlamp.2014.02.001.
46+ http://math.andrej.com/wp-content/uploads/2012/03/eff.pdf
47− (http://www.sciencedirect.com/science/article/pii/S2352220814000194)
47+
48
48
49.. [3] Ben Lippmeier. 2009. Witnessing Purity, Constancy and
49.. [3] Ben Lippmeier. 2009. Witnessing Purity, Constancy and
50 Mutability. In Proceedings of the 7th Asian Symposium on
50 Mutability. In Proceedings of the 7th Asian Symposium on
51 Programming Languages and Systems (APLAS '09), Zhenjiang Hu
51 Programming Languages and Systems (APLAS '09), Zhenjiang Hu
52 (Ed.). Springer-Verlag, Berlin, Heidelberg,
52 (Ed.). Springer-Verlag, Berlin, Heidelberg,
53 95-110. DOI=10.1007/978-3-642-10672-9_9
53 95-110. DOI=10.1007/978-3-642-10672-9_9
54− http://dx.doi.org/10.1007/978-3-642-10672-9_9
54+ http://link.springer.com/chapter/10.1007%2F978-3-642-10672-9_9
55+
55
56
56.. [4] Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in
57.. [4] Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in
57 action. SIGPLAN Not. 48, 9 (September 2013),
58 action. SIGPLAN Not. 48, 9 (September 2013),
58 145-158. DOI=10.1145/2544174.2500590
59 145-158. DOI=10.1145/2544174.2500590
59− http://doi.acm.org/10.1145/2544174.2500590
60+ https://dl.acm.org/citation.cfm?doid=2544174.2500590
60
61
61.. [5] Martin Hyland, Gordon Plotkin, John Power, Combining effects:
62.. [5] Martin Hyland, Gordon Plotkin, John Power, Combining effects:
62 Sum and tensor, Theoretical Computer Science, Volume 357,
63 Sum and tensor, Theoretical Computer Science, Volume 357,
63 Issues 1–3, 25 July 2006, Pages 70-99, ISSN 0304-3975,
64 Issues 1–3, 25 July 2006, Pages 70-99, ISSN 0304-3975,
64− http://dx.doi.org/10.1016/j.tcs.2006.03.013.
65− (http://www.sciencedirect.com/science/article/pii/S0304397506002659)
65+ (https://www.sciencedirect.com/science/article/pii/S0304397506002659)
66
66
67.. [6] Paul Blain Levy. 2004. Call-By-Push-Value: A
67.. [6] Paul Blain Levy. 2004. Call-By-Push-Value: A
68 Functional/Imperative Synthesis (Semantics Structures in
68 Functional/Imperative Synthesis (Semantics Structures in
docs/effects/introduction.rst+1−1
@@ -3,7 +3,7 @@ Introduction
3************
3************
4
4
5Pure functional languages with dependent types such as `Idris
5Pure functional languages with dependent types such as `Idris
6−<http://idris-lang.org/>`_ support reasoning about programs directly
6+<http://www.idris-lang.org/>`_ support reasoning about programs directly
7in the type system, promising that we can *know* a program will run
7in the type system, promising that we can *know* a program will run
8correctly (i.e. according to the specification in its type) simply
8correctly (i.e. according to the specification in its type) simply
9because it compiles. Realistically, though, things are not so simple:
9because it compiles. Realistically, though, things are not so simple:
docs/effects/state.rst+8−6
@@ -83,7 +83,7 @@ effectful program ``f`` has a type of the following form:
83
83
84.. code-block:: idris
84.. code-block:: idris
85
85
86− f : (x1 : a1) -> (x2 : a2) -> ... -> Eff t effs
86+ f : (x1 : a1) -> (x2 : a2) -> ... -> Eff t effs
87
87
88That is, the return type gives the effects that ``f`` supports
88That is, the return type gives the effects that ``f`` supports
89(``effs``, of type ``List EFFECT``) and the type the computation
89(``effs``, of type ``List EFFECT``) and the type the computation
@@ -419,7 +419,7 @@ underlying type ``EffM``:
419
419
420 EffM : (m : Type -> Type) -> (t : Type)
420 EffM : (m : Type -> Type) -> (t : Type)
421 -> (List EFFECT)
421 -> (List EFFECT)
422− -> (t -> List EFFECT) -> Type
422+ -> (t -> List EFFECT) -> Type
423
423
424This is more general than the types we have been writing so far. It is
424This is more general than the types we have been writing so far. It is
425parameterised over an underying computation context ``m``, a
425parameterised over an underying computation context ``m``, a
@@ -443,15 +443,15 @@ operations which can change the set of available effects are:
443 possible.
443 possible.
444
444
445While powerful, this can make uses of the ``EffM`` type hard to read.
445While powerful, this can make uses of the ``EffM`` type hard to read.
446−Therefore the library provides an overloaded function ``Eff``
446+Therefore the library provides an overloaded function ``Eff``
447There are the following three versions:
447There are the following three versions:
448
448
449.. code-block:: idris
449.. code-block:: idris
450
450
451 SimpleEff.Eff : (t : Type) -> (input_effs : List EFFECT) -> Type
451 SimpleEff.Eff : (t : Type) -> (input_effs : List EFFECT) -> Type
452− TransEff.Eff : (t : Type) -> (input_effs : List EFFECT) ->
452+ TransEff.Eff : (t : Type) -> (input_effs : List EFFECT) ->
453 (output_effs : List EFFECT) -> Type
453 (output_effs : List EFFECT) -> Type
454− DepEff.Eff : (t : Type) -> (input_effs : List EFFECT) ->
454+ DepEff.Eff : (t : Type) -> (input_effs : List EFFECT) ->
455 (output_effs_fn : x -> List EFFECT) -> Type
455 (output_effs_fn : x -> List EFFECT) -> Type
456
456
457So far, we have used only the first version, ``SimpleEff.Eff``, which
457So far, we have used only the first version, ``SimpleEff.Eff``, which
@@ -521,7 +521,9 @@ the ``new`` function, though this is beyond the scope of this tutorial.
521.. [3] Edwin Brady. 2013. Programming and reasoning with algebraic
521.. [3] Edwin Brady. 2013. Programming and reasoning with algebraic
522 effects and dependent types. SIGPLAN Not. 48, 9 (September
522 effects and dependent types. SIGPLAN Not. 48, 9 (September
523 2013), 133-144. DOI=10.1145/2544174.2500581
523 2013), 133-144. DOI=10.1145/2544174.2500581
524− http://doi.acm.org/10.1145/2544174.2500581
524+ http://dl.acm.org/citation.cfm?doid=2544174.2500581
525+
526+
525
527
526.. |image| image:: ../image/effects-tree.png
528.. |image| image:: ../image/effects-tree.png
527 :width: 500px
529 :width: 500px
docs/faq/faq.rst+1−1
@@ -150,7 +150,7 @@ names ``Float`` and ``Double`` to represent floating point numbers of
150size 32 and 64 respectivly. Newer languages such as Rust and Julia
150size 32 and 64 respectivly. Newer languages such as Rust and Julia
151have begun to follow the naming scheme described in `IEE Standard for
151have begun to follow the naming scheme described in `IEE Standard for
152Floating-Point Arithmetic (IEEE 754)
152Floating-Point Arithmetic (IEEE 754)
153−<http://en.wikipedia.org/wiki/IEEE_floating_point>`_. This describes
153+<https://en.wikipedia.org/wiki/IEEE_floating_point>`_. This describes
154single and double precision numbers as ``Float32`` and ``Float64``;
154single and double precision numbers as ``Float32`` and ``Float64``;
155the size is described in the type name.
155the size is described in the type name.
156
156
docs/reference/erasure.rst+1−1
@@ -29,7 +29,7 @@ and we can use irrelevance-related methods to achieve erasure.
29However, sometimes we want to erase *indices* and this is where the
29However, sometimes we want to erase *indices* and this is where the
30traditional approaches stop being useful, mainly for reasons described
30traditional approaches stop being useful, mainly for reasons described
31in the `original proposal
31in the `original proposal
32−<https://github.com/idris-lang/Idris-dev/wiki/Egg-%232%3A-Erasure-annotations#prop-is-cumbersome-coq>`__.
32+<https://github.com/idris-lang/Idris-dev/wiki/Egg-%232%3A-Erasure-annotations>`__.
33
33
34.. code-block:: idris
34.. code-block:: idris
35
35
docs/reference/uniqueness-types.rst+1−1
@@ -15,7 +15,7 @@ They are inspired by linear types, `Uniqueness Types
15<https://en.wikipedia.org/wiki/Uniqueness_type>`__ in the `Clean
15<https://en.wikipedia.org/wiki/Uniqueness_type>`__ in the `Clean
16<http://wiki.clean.cs.ru.nl/Clean>`__ programming language, and
16<http://wiki.clean.cs.ru.nl/Clean>`__ programming language, and
17ownership types and borrowed pointers in the `Rust
17ownership types and borrowed pointers in the `Rust
18−<http://www.rust-lang.org/>`__ programming language.
18+<https://www.rust-lang.org/>`__ programming language.
19
19
20Some things we hope to be able to do eventually with uniqueness types
20Some things we hope to be able to do eventually with uniqueness types
21include:
21include:
docs/tutorial/conclusions.rst+1−1
@@ -7,7 +7,7 @@ Further Reading
7Further information about Idris programming, and programming with
7Further information about Idris programming, and programming with
8dependent types in general, can be obtained from various sources:
8dependent types in general, can be obtained from various sources:
9
9
10−- The Idris web site (http://idris-lang.org/) and by asking
10+- The Idris web site (http://www.idris-lang.org/) and by asking
11 questions on the mailing list.
11 questions on the mailing list.
12
12
13- The IRC channel ``#idris``, on
13- The IRC channel ``#idris``, on
docs/tutorial/interactive.rst+1−1
@@ -20,7 +20,7 @@ hole, and even a basic proof search mechanism. In this
20section, we explain how these features can be exploited by a text
20section, we explain how these features can be exploited by a text
21editor, and specifically how to do so in `Vim
21editor, and specifically how to do so in `Vim
22<https://github.com/idris-hackers/idris-vim>`_. An interactive mode
22<https://github.com/idris-hackers/idris-vim>`_. An interactive mode
23−for `Emacs <https://github.com/idris-hackers/idris-emacs>`_ is also
23+for `Emacs <https://github.com/idris-hackers/idris-mode>`_ is also
24available.
24available.
25
25
26
26
docs/tutorial/testing.rst+2−2
@@ -23,8 +23,8 @@ does not aggregate test results.
23
23
24For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
24For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
25
25
26+.. name: Math/NumOps.idr
26.. code-block:: idris
27.. code-block:: idris
27− :caption: Math/NumOps.idr
28
28
29 module Maths.NumOps
29 module Maths.NumOps
30
30
@@ -36,8 +36,8 @@ For example, lets take the following list of functions that are defined in a mod
36
36
37A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
37A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
38
38
39+.. name: Math/TestOps.idr
39.. code-block:: idris
40.. code-block:: idris
40− :caption: Math/TestOps.idr
41
41
42 module Test.NumOps
42 module Test.NumOps
43
43
docs/tutorial/typesfuns.rst+145−131
@@ -247,6 +247,7 @@ So, for example, the following definitions are legal:
247 d y = c (y + 1 + z y)
247 d y = c (y + 1 + z y)
248 where z w = y + w
248 where z w = y + w
249
249
250+
250Dependent Types
251Dependent Types
251===============
252===============
252
253
@@ -393,10 +394,10 @@ elements. ``Fin`` is indexed by a ``Nat``, which represents the number
393of elements in the set. Since we can’t construct an element of an
394of elements in the set. Since we can’t construct an element of an
394empty set, neither constructor targets ``Fin Z``.
395empty set, neither constructor targets ``Fin Z``.
395
396
396−As mentioned above, a useful application of the ``Fin`` family is to represent bounded
397+As mentioned above, a useful application of the ``Fin`` family is to
397−natural numbers. Since the first ``n`` natural numbers form a finite
398+represent bounded natural numbers. Since the first ``n`` natural
398−set of ``n`` elements, we can treat ``Fin n`` as the set of integers
399+numbers form a finite set of ``n`` elements, we can treat ``Fin n`` as
399−greater than or equal to zero and less than ``n``.
400+the set of integers greater than or equal to zero and less than ``n``.
400
401
401For example, the following function which looks up an element in a
402For example, the following function which looks up an element in a
402``Vect``, by a bounded index given as a ``Fin n``, is defined in the
403``Vect``, by a bounded index given as a ``Fin n``, is defined in the
@@ -505,7 +506,7 @@ appear within the block:
505 There : Elem x xs -> Elem x (y :: xs)
506 There : Elem x xs -> Elem x (y :: xs)
506
507
507Note: Declaration Order and ``mutual`` blocks
508Note: Declaration Order and ``mutual`` blocks
508−---------------------------------------------
509+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
509
510
510In general, functions and data types must be defined before use, since
511In general, functions and data types must be defined before use, since
511dependent types allow functions to appear as part of types, and their
512dependent types allow functions to appear as part of types, and their
@@ -737,7 +738,7 @@ remember that Idris is still in development, so if you don’t see
737the function you need, please feel free to add it and submit a patch!
738the function you need, please feel free to add it and submit a patch!
738
739
739Aside: Anonymous functions and operator sections
740Aside: Anonymous functions and operator sections
740−------------------------------------------------
741+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
741
742
742There are actually neater ways to write the above expression. One way
743There are actually neater ways to write the above expression. One way
743would be to use an anonymous function:
744would be to use an anonymous function:
@@ -797,8 +798,8 @@ simply ``b``. Since the default value might not be used, we mark it as
797``Lazy`` in case it is a large expression where evaluating it then
798``Lazy`` in case it is a large expression where evaluating it then
798discarding it would be wasteful.
799discarding it would be wasteful.
799
800
800−Tuples and Dependent Pairs
801+Tuples
801−--------------------------
802+------
802
803
803Values can be paired with the following built-in data type:
804Values can be paired with the following built-in data type:
804
805
@@ -894,6 +895,142 @@ intermediate values:
894
895
895We will see more on ``with`` notation later.
896We will see more on ``with`` notation later.
896
897
898+
899+Records
900+-------
901+
902+*Records* are data types which collect several values (the record's
903+*fields*) together. Idris provides syntax for defining records and
904+*automatically generating field access and update functions*. Unlike
905+*the syntax used for data structures, records in Idris follow a
906+*different syntax to that seen with Haskell. For example, we can
907+*represent a person's name and age in a record:
908+
909+.. code-block:: idris
910+
911+ record Person where
912+ constructor MkPerson
913+ firstName, middleName, lastName : String
914+ age : Int
915+
916+ fred : Person
917+ fred = MkPerson "Fred" "Joe" "Bloggs" 30
918+
919+
920+The constructor name is provided using the ``constructor`` keyword,
921+and the *fields* are then given which are in an indented block
922+following the `where` keyword (here, ``firstName``, ``middleName``,
923+``lastName``, and ``age``). You can declare multiple fields on a
924+single line, provided that they have the same type. The field names
925+can be used to access the field values:
926+
927+::
928+
929+ *record> firstName fred
930+ "Fred" : String
931+ *record> age fred
932+ 30 : Int
933+ *record> :t firstName
934+ firstName : Person -> String
935+
936+We can also use the field names to update a record (or, more
937+precisely, produce a copy of the record with the given fields
938+updated):
939+
940+.. code-block:: bash
941+
942+ *record> record { firstName = "Jim" } fred
943+ MkPerson "Jim" "Joe" "Bloggs" 30 : Person
944+ *record> record { firstName = "Jim", age = 20 } fred
945+ MkPerson "Jim" "Joe" "Bloggs" 20 : Person
946+
947+The syntax ``record { field = val, ... }`` generates a function which
948+updates the given fields in a record.
949+
950+Records, and fields within records, can have dependent types. Updates
951+are allowed to change the type of a field, provided that the result is
952+well-typed.
953+
954+.. code-block:: idris
955+
956+ record Class where
957+ constructor ClassInfo
958+ students : Vect n Person
959+ className : String
960+
961+It is safe to update the ``students`` field to a vector of a different
962+length because it will not affect the type of the record:
963+
964+.. code-block:: idris
965+
966+ addStudent : Person -> Class -> Class
967+ addStudent p c = record { students = p :: students c } c
968+
969+::
970+
971+ *record> addStudent fred (ClassInfo [] "CS")
972+ ClassInfo [MkPerson "Fred" "Joe" "Bloggs" 30] "CS" : Class
973+
974+
975+Nested record update
976+~~~~~~~~~~~~~~~~~~~~
977+
978+Idris also provides a convenient syntax for accessing and updating
979+nested records. For example, if a field is accessible with the
980+expression ``c (b (a x))``, it can be updated using the following
981+syntax:
982+
983+.. code-block:: idris
984+
985+ record { a->b->c = val } x
986+
987+This returns a new record, with the field accessed by the path
988+``a->b->c`` set to ``x``. The syntax is first class, i.e. ``record {
989+a->b->c = val }`` itself has a function type. Symmetrically, the field
990+can also be accessed with the following syntax:
991+
992+.. code-block:: idris
993+
994+ record { a->b->c } x
995+
996+
997+Dependent Records
998+-----------------
999+
1000+Records can also be dependent on values. Records *parameters*, which
1001+are not subject to field updates. The parameters appear as arguments
1002+to the resulting type, and are written following the record type
1003+name. For example, a pair type could be defined as follows:
1004+
1005+.. code-block:: idris
1006+
1007+ record Prod a b where
1008+ constructor Times
1009+ fst : a
1010+ snd : b
1011+
1012+
1013+Using the class record from the original introduction to records. The
1014+size of the class can be restricted using a ``Vect`` and the size
1015+promoted to the type level by parameterising the record with the size.
1016+Foe example:
1017+
1018+
1019+.. code-block:: idris
1020+
1021+ record SizedClass (size : Nat) where
1022+ constructor SizedClassInfo
1023+ students : Vect size Person
1024+ className : String
1025+
1026+**Note** that it is no longer possible to use the ``addStudent``
1027+method from earlier as that would change the size of the class. To provide an add student the function must specify in the type that the size of the class has been increased by one. As the size if specified using natural numbers, the new value can be incremeated using the successor constructor.
1028+
1029+.. code-block:: idris
1030+
1031+ addStudent : Person -> SizedClass n -> SizedClass (S n)
1032+ addStudent p c = record { students = p :: students c } c
1033+
897.. _sect-more-expr:
1034.. _sect-more-expr:
898
1035
899More Expressions
1036More Expressions
@@ -1004,126 +1141,3 @@ matching ``let`` and lambda bindings. It will *only* work if:
1004- The type of the result is "known". i.e. the type of the expression
1141- The type of the result is "known". i.e. the type of the expression
1005 can be determined *without* type checking the ``case``-expression
1142 can be determined *without* type checking the ``case``-expression
1006 itself.
1143 itself.
1007−
1008−Dependent Records
1009−=================
1010−
1011−*Records* are data types which collect several values (the record's
1012−*fields*) together. Idris provides syntax for defining records and
1013−*automatically generating field access and update functions*. For
1014−example, we can represent a person's name and age in a record:
1015−
1016−.. code-block:: idris
1017−
1018− record Person where
1019− constructor MkPerson
1020− firstName, middleName, lastName : String
1021− age : Int
1022−
1023− fred : Person
1024− fred = MkPerson "Fred" "Joe" "Bloggs" 30
1025−
1026−Records can have *parameters*, which are listed between the record
1027−name and the ``where`` keyword, and *fields*, which are in an indented
1028−block following the `where` keyword (here, ``firstName``, ``middleName``,
1029−``lastName``, and ``age``). You can declare multiple fields on a single
1030−line, provided that they have the same type. The constructor name is
1031−provided after the ``constructor`` keyword. The field names can be used to
1032−access the field values:
1033−
1034−::
1035−
1036− *record> firstName fred
1037− "Fred" : String
1038− *record> age fred
1039− 30 : Int
1040− *record> :t firstName
1041− firstName : Person -> String
1042−
1043−We can also use the field names to update a record (or, more
1044−precisely, produce a copy of the record with the given fields
1045−updated):
1046−
1047−.. code-block:: bash
1048−
1049− *record> record { firstName = "Jim" } fred
1050− MkPerson "Jim" "Joe" "Bloggs" 30 : Person
1051− *record> record { firstName = "Jim", age = 20 } fred
1052− MkPerson "Jim" "Joe" "Bloggs" 20 : Person
1053−
1054−The syntax ``record { field = val, ... }`` generates a function which
1055−updates the given fields in a record.
1056−
1057−Records, and fields within records, can have dependent types. Updates
1058−are allowed to change the type of a field, provided that the result is
1059−well-typed.
1060−
1061−.. code-block:: idris
1062−
1063− record Class where
1064− constructor ClassInfo
1065− students : Vect n Person
1066− className : String
1067−
1068−It is safe to update the ``students`` field to a vector of a different
1069−length because it will not affect the type of the record:
1070−
1071−.. code-block:: idris
1072−
1073− addStudent : Person -> Class -> Class
1074− addStudent p c = record { students = p :: students c } c
1075−
1076−::
1077−
1078− *record> addStudent fred (ClassInfo [] "CS")
1079− ClassInfo [MkPerson "Fred" "Joe" "Bloggs" 30] "CS" : Class
1080−
1081−Nested record update
1082−--------------------
1083−
1084−Idris also provides a convenient syntax for accessing and updating
1085−nested records. For example, if a field is accessible with the
1086−expression ``c (b (a x))``, it can be updated using the following
1087−syntax:
1088−
1089−.. code-block:: idris
1090−
1091− record { a->b->c = val } x
1092−
1093−This returns a new record, with the field accessed by the path
1094−``a->b->c`` set to ``x``. The syntax is first class, i.e. ``record {
1095−a->b->c = val }`` itself has a function type. Symmetrically, the field
1096−can also be accessed with the following syntax:
1097−
1098−.. code-block:: idris
1099−
1100− record { a->b->c } x
1101−
1102−Parameters and Fields
1103−---------------------
1104−
1105−Records can have *parameters*, which are not subject to field
1106−updates. The parameters appear as arguments to the resulting type, and
1107−are written following the record type name. For example, a pair type
1108−could be defined as follows:
1109−
1110−.. code-block:: idris
1111−
1112− record Prod a b where
1113− constructor Times
1114− fst : a
1115− snd : b
1116−
1117−The parameters to a record type need not be types. For example, we can
1118−restrict the size of classes using a ``Nat`` parameter to the
1119−``Class`` record:
1120−
1121−.. code-block:: idris
1122−
1123− record SizedClass (size : Nat) where
1124− constructor SizedClassInfo
1125− students : Vect size Person
1126− className : String
1127−
1128−Note that it is no longer possible to write ``addStudent`` for this
1129−type, as that would change the size of the class.