-
Notifications
You must be signed in to change notification settings - Fork 5
/
Hashkell_2010_Language_Report.rst
22959 lines (17251 loc) · 867 KB
/
Hashkell_2010_Language_Report.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. code-block:: bash
#!/usr/bin/env bash
# https://www.haskell.org/onlinereport/haskell2010
while read it; do
pandoc -r html "https://haskell.org/onlinereport/haskell2010/$it" -t rst >> $0
done << EOF
haskellli1.html
haskellli2.html
haskellpa1.html
haskellch1.html
haskellch2.html
haskellch3.html
haskellch4.html
haskellch5.html
haskellch6.html
haskellch7.html
haskellch8.html
haskellch9.html
haskellch10.html
haskellch11.html
haskellch12.html
haskellpa2.html
haskellch13.html
haskellch14.html
haskellch15.html
haskellch16.html
haskellch17.html
haskellch18.html
haskellch19.html
haskellch20.html
haskellch21.html
haskellch22.html
haskellch23.html
haskellch24.html
haskellch25.html
haskellch26.html
haskellch27.html
haskellch28.html
haskellch29.html
haskellch30.html
haskellch31.html
haskellch32.html
haskellch33.html
haskellch34.html
haskellch35.html
haskellch36.html
haskellch37.html
haskellch38.html
haskellch39.html
haskellch40.html
haskellch41.html
haskellch42.html
haskellli3.html
EOF
exit
.. container:: center
| Haskell 2010
| Language Report
.. container:: center
| Simon Marlow
| (editor)
.. container:: center
Copyright notice.
The authors and publisher intend this Report to belong to the entire
Haskell community, and grant permission to copy and distribute it for
any purpose, provided that it is reproduced in its entirety, including
this Notice. Modified versions of this Report may also be copied and
distributed for any purpose, provided that the modified version is
clearly presented as such, and that it does not claim to be a definition
of the language Haskell 2010.
.. container:: tableofcontents
* `Contents <#xs01>`__
* `Preface <#xs02>`__
* `Goals <#xs03>`__
* `Haskell 2010: language and libraries <#xs04>`__
* `Extensions to Haskell 98 <#xs05>`__
* `Haskell Resources <#xs06>`__
* `Building the language <#xs07>`__
* I `The Haskell 2010 Language <#xsI>`__
* 1 `Introduction <#xs1>`__
* 1.1 `Program Structure <#xs1.1>`__
* 1.2 `The Haskell Kernel <#xs1.2>`__
* 1.3 `Values and Types <#xs1.3>`__
* 1.4 `Namespaces <#xs1.4>`__
* 2 `Lexical Structure <#xs2>`__
* 2.1 `Notational Conventions <#xs2.1>`__
* 2.2 `Lexical Program Structure <#xs2.2>`__
* 2.3 `Comments <#xs2.3>`__
* 2.4 `Identifiers and Operators <#xs2.4>`__
* 2.5 `Numeric Literals <#xs2.5>`__
* 2.6 `Character and String Literals <#xs2.6>`__
* 2.7 `Layout <#xs2.7>`__
* 3 `Expressions <#xs3>`__
* 3.1 `Errors <#xs3.1>`__
* 3.2 `Variables, Constructors, Operators, and Literals <#xs3.2>`__
* 3.3 `Curried Applications and Lambda Abstractions <#xs3.3>`__
* 3.4 `Operator Applications <#xs3.4>`__
* 3.5 `Sections <#xs3.5>`__
* 3.6 `Conditionals <#xs3.6>`__
* 3.7 `Lists <#xs3.7>`__
* 3.8 `Tuples <#xs3.8>`__
* 3.9 `Unit Expressions and Parenthesized Expressions <#xs3.9>`__
* 3.10 `Arithmetic Sequences <#xs3.10>`__
* 3.11 `List Comprehensions <#xs3.11>`__
* 3.12 `Let Expressions <#xs3.12>`__
* 3.13 `Case Expressions <#xs3.13>`__
* 3.14 `Do Expressions <#xs3.14>`__
* 3.15 `Datatypes with Field Labels <#xs3.15>`__
* 3.16 `Expression Type-Signatures <#xs3.16>`__
* 3.17 `Pattern Matching <#xs3.17>`__
* 4 `Declarations and Bindings <#xs4>`__
* 4.1 `Overview of Types and Classes <#xs4.1>`__
* 4.2 `User-Defined Datatypes <#xs4.2>`__
* 4.3 `Type Classes and Overloading <#xs4.3>`__
* 4.4 `Nested Declarations <#xs4.4>`__
* 4.5 `Static Semantics of Function and Pattern Bindings <#xs4.5>`__
* 4.6 `Kind Inference <#xs4.6>`__
* 5 `Modules <#xs5>`__
* 5.1 `Module Structure <#xs5.1>`__
* 5.2 `Export Lists <#xs5.2>`__
* 5.3 `Import Declarations <#xs5.3>`__
* 5.4 `Importing and Exporting Instance Declarations <#xs5.4>`__
* 5.5 `Name Clashes and Closure <#xs5.5>`__
* 5.6 `Standard Prelude <#xs5.6>`__
* 5.7 `Separate Compilation <#xs5.7>`__
* 5.8 `Abstract Datatypes <#xs5.8>`__
* 6 `Predefined Types and Classes <#xs6>`__
* 6.1 `Standard Haskell Types <#xs6.1>`__
* 6.2 `Strict Evaluation <#xs6.2>`__
* 6.3 `Standard Haskell Classes <#xs6.3>`__
* 6.4 `Numbers <#xs6.4>`__
* 7 `Basic Input/Output <#xs7>`__
* 7.1 `Standard I/O Functions <#xs7.1>`__
* 7.2 `Sequencing I/O Operations <#xs7.2>`__
* 7.3 `Exception Handling in the I/O Monad <#xs7.3>`__
* 8 `Foreign Function Interface <#xs8>`__
* 8.1 `Foreign Languages <#xs8.1>`__
* 8.2 `Contexts <#xs8.2>`__
* 8.3 `Lexical Structure <#xs8.3>`__
* 8.4 `Foreign Declarations <#xs8.4>`__
* 8.5 `Specification of External Entities <#xs8.5>`__
* 8.6 `Marshalling <#xs8.6>`__
* 8.7 `The External C Interface <#xs8.7>`__
* 9 `Standard Prelude <#xs9>`__
* 9.1 `Prelude PreludeList <#xs9.1>`__
* 9.2 `Prelude PreludeText <#xs9.2>`__
* 9.3 `Prelude PreludeIO <#xs9.3>`__
* 10 `Syntax Reference <#xs10>`__
* 10.1 `Notational Conventions <#xs10.1>`__
* 10.2 `Lexical Syntax <#xs10.2>`__
* 10.3 `Layout <#xs10.3>`__
* 10.4 `Literate comments <#xs10.4>`__
* 10.5 `Context-Free Syntax <#xs10.5>`__
* 10.6 `Fixity Resolution <#xs10.6>`__
* 11 `Specification of Derived Instances <#xs11>`__
* 11.1 `Derived instances of Eq and Ord <#xs11.1>`__
* 11.2 `Derived instances of Enum <#xs11.2>`__
* 11.3 `Derived instances of Bounded <#xs11.3>`__
* 11.4 `Derived instances of Read and Show <#xs11.4>`__
* 11.5 `An Example <#xs11.5>`__
* 12 `Compiler Pragmas <#xs12>`__
* 12.1 `Inlining <#xs12.1>`__
* 12.2 `Specialization <#xs12.2>`__
* 12.3 `Language extensions <#xs12.3>`__
* II `The Haskell 2010 Libraries <#xsII>`__
* 13 `Control.Monad <#xs13>`__
* 13.1 `Functor and monad classes <#xs13.1>`__
* 13.2 `Functions <#xs13.2>`__
* 14 `Data.Array <#xs14>`__
* 14.1 `Immutable non-strict arrays <#xs14.1>`__
* 14.2 `Array construction <#xs14.2>`__
* 14.3 `Accessing arrays <#xs14.3>`__
* 14.4 `Incremental array updates <#xs14.4>`__
* 14.5 `Derived arrays <#xs14.5>`__
* 14.6 `Specification <#xs14.6>`__
* 15 `Data.Bits <#xs15>`__
* 16 `Data.Char <#xs16>`__
* 16.1 `Characters and strings <#xs16.1>`__
* 16.2 `Character classification <#xs16.2>`__
* 16.3 `Case conversion <#xs16.3>`__
* 16.4 `Single digit characters <#xs16.4>`__
* 16.5 `Numeric representations <#xs16.5>`__
* 16.6 `String representations <#xs16.6>`__
* 17 `Data.Complex <#xs17>`__
* 17.1 `Rectangular form <#xs17.1>`__
* 17.2 `Polar form <#xs17.2>`__
* 17.3 `Conjugate <#xs17.3>`__
* 17.4 `Specification <#xs17.4>`__
* 18 `Data.Int <#xs18>`__
* 18.1 `Signed integer types <#xs18.1>`__
* 19 `Data.Ix <#xs19>`__
* 19.1 `The Ix class <#xs19.1>`__
* 19.2 `Deriving Instances of Ix <#xs19.2>`__
* 20 `Data.List <#xs20>`__
* 20.1 `Basic functions <#xs20.1>`__
* 20.2 `List transformations <#xs20.2>`__
* 20.3 `Reducing lists (folds) <#xs20.3>`__
* 20.4 `Building lists <#xs20.4>`__
* 20.5 `Sublists <#xs20.5>`__
* 20.6 `Searching lists <#xs20.6>`__
* 20.7 `Indexing lists <#xs20.7>`__
* 20.8 `Zipping and unzipping lists <#xs20.8>`__
* 20.9 `Special lists <#xs20.9>`__
* 20.10 `Generalized functions <#xs20.10>`__
* 21 `Data.Maybe <#xs21>`__
* 21.1 `The Maybe type and operations <#xs21.1>`__
* 21.2 `Specification <#xs21.2>`__
* 22 `Data.Ratio <#xs22>`__
* 22.1 `Specification <#xs22.1>`__
* 23 `Data.Word <#xs23>`__
* 23.1 `Unsigned integral types <#xs23.1>`__
* 24 `Foreign <#xs24>`__
* 25 `Foreign.C <#xs25>`__
* 26 `Foreign.C.Error <#xs26>`__
* 26.1 `Haskell representations of errno values <#xs26.1>`__
* 27 `Foreign.C.String <#xs27>`__
* 27.1 `C strings <#xs27.1>`__
* 27.2 `C wide strings <#xs27.2>`__
* 28 `Foreign.C.Types <#xs28>`__
* 28.1 `Representations of C types <#xs28.1>`__
* 29 `Foreign.ForeignPtr <#xs29>`__
* 29.1 `Finalised data pointers <#xs29.1>`__
* 30 `Foreign.Marshal <#xs30>`__
* 31 `Foreign.Marshal.Alloc <#xs31>`__
* 31.1 `Memory allocation <#xs31.1>`__
* 32 `Foreign.Marshal.Array <#xs32>`__
* 32.1 `Marshalling arrays <#xs32.1>`__
* 33 `Foreign.Marshal.Error <#xs33>`__
* 34 `Foreign.Marshal.Utils <#xs34>`__
* 34.1 `General marshalling utilities <#xs34.1>`__
* 35 `Foreign.Ptr <#xs35>`__
* 35.1 `Data pointers <#xs35.1>`__
* 35.2 `Function pointers <#xs35.2>`__
* 35.3 `Integral types with lossless conversion to and from pointers <#xs35.3>`__
* 36 `Foreign.StablePtr <#xs36>`__
* 36.1 `Stable references to Haskell values <#xs36.1>`__
* 37 `Foreign.Storable <#xs37>`__
* 38 `Numeric <#xs38>`__
* 38.1 `Showing <#xs38.1>`__
* 38.2 `Reading <#xs38.2>`__
* 38.3 `Miscellaneous <#xs38.3>`__
* 39 `System.Environment <#xs39>`__
* 40 `System.Exit <#xs40>`__
* 41 `System.IO <#xs41>`__
* 41.1 `The IO monad <#xs41.1>`__
* 41.2 `Files and handles <#xs41.2>`__
* 41.3 `Opening and closing files <#xs41.3>`__
* 41.4 `Operations on handles <#xs41.4>`__
* 41.5 `Text input and output <#xs41.5>`__
* 42 `System.IO.Error <#xs42>`__
* 42.1 `I/O errors <#xs42.1>`__
* 42.2 `Types of I/O error <#xs42.2>`__
* 42.3 `Throwing and catching I/O errors <#xs42.3>`__
* `Bibliography <#xs42.3>`__
.. _xs01:
Contents
--------
.. container:: tableofcontents
I `The Haskell 2010 Language <#xsI>`__
1 `Introduction <#xs1>`__
1.1 `Program Structure <#xs1.1>`__
1.2 `The Haskell Kernel <#xs1.2>`__
1.3 `Values and Types <#xs1.3>`__
1.4 `Namespaces <#xs1.4>`__
2 `Lexical Structure <#xs2>`__
2.1 `Notational Conventions <#xs2.1>`__
2.2 `Lexical Program Structure <#xs2.2>`__
2.3 `Comments <#xs2.3>`__
2.4 `Identifiers and Operators <#xs2.4>`__
2.5 `Numeric Literals <#xs2.5>`__
2.6 `Character and String Literals <#xs2.6>`__
2.7 `Layout <#xs2.7>`__
3 `Expressions <#xs3>`__
3.1 `Errors <#xs3.1>`__
3.2 `Variables, Constructors, Operators, and Literals <#xs3.2>`__
3.3 `Curried Applications and Lambda Abstractions <#xs3.3>`__
3.4 `Operator Applications <#xs3.4>`__
3.5 `Sections <#xs3.5>`__
3.6 `Conditionals <#xs3.6>`__
3.7 `Lists <#xs3.7>`__
3.8 `Tuples <#xs3.8>`__
3.9 `Unit Expressions and Parenthesized Expressions <#xs3.9>`__
3.10 `Arithmetic Sequences <#xs3.10>`__
3.11 `List Comprehensions <#xs3.11>`__
3.12 `Let Expressions <#xs3.12>`__
3.13 `Case Expressions <#xs3.13>`__
3.14 `Do Expressions <#xs3.14>`__
3.15 `Datatypes with Field Labels <#xs3.15>`__
3.15.1 `Field Selection <#xs3.15.1>`__
3.15.2 `Construction Using Field Labels <#xs3.15.2>`__
3.15.3 `Updates Using Field Labels <#xs3.15.3>`__
3.16 `Expression Type-Signatures <#xs3.16>`__
3.17 `Pattern Matching <#xs3.17>`__
3.17.1 `Patterns <#xs3.17.1>`__
3.17.2 `Informal Semantics of Pattern Matching <#xs3.17.2>`__
3.17.3 `Formal Semantics of Pattern Matching <#xs3.17.3>`__
4 `Declarations and Bindings <#xs4>`__
4.1 `Overview of Types and Classes <#xs4.1>`__
4.1.1 `Kinds <#xs4.1.1>`__
4.1.2 `Syntax of Types <#xs4.1.2>`__
4.1.3 `Syntax of Class Assertions and Contexts <#xs4.1.3>`__
4.1.4 `Semantics of Types and Classes <#xs4.1.4>`__
4.2 `User-Defined Datatypes <#xs4.2>`__
4.2.1 `Algebraic Datatype Declarations <#xs4.2.1>`__
4.2.2 `Type Synonym Declarations <#xs4.2.2>`__
4.2.3 `Datatype Renamings <#xs4.2.3>`__
4.3 `Type Classes and Overloading <#xs4.3>`__
4.3.1 `Class Declarations <#xs4.3.1>`__
4.3.2 `Instance Declarations <#xs4.3.2>`__
4.3.3 `Derived Instances <#xs4.3.3>`__
4.3.4 `Ambiguous Types, and Defaults for Overloaded Numeric Operations <#xs4.3.4>`__
4.4 `Nested Declarations <#xs4.4>`__
4.4.1 `Type Signatures <#xs4.4.1>`__
4.4.2 `Fixity Declarations <#xs4.4.2>`__
4.4.3 `Function and Pattern Bindings <#xs4.4.3>`__
4.4.3.1 `Function bindings <#xs4.4.3.1>`__
4.4.3.2 `Pattern bindings <#xs4.4.3.2>`__
4.5 `Static Semantics of Function and Pattern Bindings <#xs4.5>`__
4.5.1 `Dependency Analysis <#xs4.5.1>`__
4.5.2 `Generalization <#xs4.5.2>`__
4.5.3 `Context Reduction Errors <#xs4.5.3>`__
4.5.4 `Monomorphism <#xs4.5.4>`__
4.5.5 `The Monomorphism Restriction <#xs4.5.5>`__
4.6 `Kind Inference <#xs4.6>`__
5 `Modules <#xs5>`__
5.1 `Module Structure <#xs5.1>`__
5.2 `Export Lists <#xs5.2>`__
5.3 `Import Declarations <#xs5.3>`__
5.3.1 `What is imported <#xs5.3.1>`__
5.3.2 `Qualified import <#xs5.3.2>`__
5.3.3 `Local aliases <#xs5.3.3>`__
5.3.4 `Examples <#xs5.3.4>`__
5.4 `Importing and Exporting Instance Declarations <#xs5.4>`__
5.5 `Name Clashes and Closure <#xs5.5>`__
5.5.1 `Qualified names <#xs5.5.1>`__
5.5.2 `Name clashes <#xs5.5.2>`__
5.5.3 `Closure <#xs5.5.3>`__
5.6 `Standard Prelude <#xs5.6>`__
5.6.1 `The Prelude Module <#xs5.6.1>`__
5.6.2 `Shadowing Prelude Names <#xs5.6.2>`__
5.7 `Separate Compilation <#xs5.7>`__
5.8 `Abstract Datatypes <#xs5.8>`__
6 `Predefined Types and Classes <#xs6>`__
6.1 `Standard Haskell Types <#xs6.1>`__
6.1.1 `Booleans <#xs6.1.1>`__
6.1.2 `Characters and Strings <#xs6.1.2>`__
6.1.3 `Lists <#xs6.1.3>`__
6.1.4 `Tuples <#xs6.1.4>`__
6.1.5 `The Unit Datatype <#xs6.1.5>`__
6.1.6 `Function Types <#xs6.1.6>`__
6.1.7 `The IO and IOError Types <#xs6.1.7>`__
6.1.8 `Other Types <#xs6.1.8>`__
6.2 `Strict Evaluation <#xs6.2>`__
6.3 `Standard Haskell Classes <#xs6.3>`__
6.3.1 `The Eq Class <#xs6.3.1>`__
6.3.2 `The Ord Class <#xs6.3.2>`__
6.3.3 `The Read and Show Classes <#xs6.3.3>`__
6.3.4 `The Enum Class <#xs6.3.4>`__
6.3.5 `The Functor Class <#xs6.3.5>`__
6.3.6 `The Monad Class <#xs6.3.6>`__
6.3.7 `The Bounded Class <#xs6.3.7>`__
6.4 `Numbers <#xs6.4>`__
6.4.1 `Numeric Literals <#xs6.4.1>`__
6.4.2 `Arithmetic and Number-Theoretic Operations <#xs6.4.2>`__
6.4.3 `Exponentiation and Logarithms <#xs6.4.3>`__
6.4.4 `Magnitude and Sign <#xs6.4.4>`__
6.4.5 `Trigonometric Functions <#xs6.4.5>`__
6.4.6 `Coercions and Component Extraction <#xs6.4.6>`__
7 `Basic Input/Output <#xs7>`__
7.1 `Standard I/O Functions <#xs7.1>`__
7.2 `Sequencing I/O Operations <#xs7.2>`__
7.3 `Exception Handling in the I/O Monad <#xs7.3>`__
8 `Foreign Function Interface <#xs8>`__
8.1 `Foreign Languages <#xs8.1>`__
8.2 `Contexts <#xs8.2>`__
8.2.1 `Cross Language Type Consistency <#xs8.2.1>`__
8.3 `Lexical Structure <#xs8.3>`__
8.4 `Foreign Declarations <#xs8.4>`__
8.4.1 `Calling Conventions <#xs8.4.1>`__
8.4.2 `Foreign Types <#xs8.4.2>`__
8.4.3 `Import Declarations <#xs8.4.3>`__
8.4.4 `Export Declarations <#xs8.4.4>`__
8.5 `Specification of External Entities <#xs8.5>`__
8.5.1 `Standard C Calls <#xs8.5.1>`__
8.5.2 `Win32 API Calls <#xs8.5.2>`__
8.6 `Marshalling <#xs8.6>`__
8.7 `The External C Interface <#xs8.7>`__
9 `Standard Prelude <#xs9>`__
9.1 `Prelude PreludeList <#xs9.1>`__
9.2 `Prelude PreludeText <#xs9.2>`__
9.3 `Prelude PreludeIO <#xs9.3>`__
10 `Syntax Reference <#xs10>`__
10.1 `Notational Conventions <#xs10.1>`__
10.2 `Lexical Syntax <#xs10.2>`__
10.3 `Layout <#xs10.3>`__
10.4 `Literate comments <#xs10.4>`__
10.5 `Context-Free Syntax <#xs10.5>`__
10.6 `Fixity Resolution <#xs10.6>`__
11 `Specification of Derived Instances <#xs11>`__
11.1 `Derived instances of Eq and Ord <#xs11.1>`__
11.2 `Derived instances of Enum <#xs11.2>`__
11.3 `Derived instances of Bounded <#xs11.3>`__
11.4 `Derived instances of Read and Show <#xs11.4>`__
11.5 `An Example <#xs11.5>`__
12 `Compiler Pragmas <#xs12>`__
12.1 `Inlining <#xs12.1>`__
12.2 `Specialization <#xs12.2>`__
12.3 `Language extensions <#xs12.3>`__
II `The Haskell 2010 Libraries <#xsII>`__
13 `Control.Monad <#xs13>`__
13.1 `Functor and monad classes <#xs13.1>`__
13.2 `Functions <#xs13.2>`__
13.2.1 `Naming conventions <#xs13.2.1>`__
13.2.2 `Basic Monad functions <#xs13.2.2>`__
13.2.3 `Generalisations of list functions <#xs13.2.3>`__
13.2.4 `Conditional execution of monadic expressions <#xs13.2.4>`__
13.2.5 `Monadic lifting operators <#xs13.2.5>`__
14 `Data.Array <#xs14>`__
14.1 `Immutable non-strict arrays <#xs14.1>`__
14.2 `Array construction <#xs14.2>`__
14.3 `Accessing arrays <#xs14.3>`__
14.4 `Incremental array updates <#xs14.4>`__
14.5 `Derived arrays <#xs14.5>`__
14.6 `Specification <#xs14.6>`__
15 `Data.Bits <#xs15>`__
16 `Data.Char <#xs16>`__
16.1 `Characters and strings <#xs16.1>`__
16.2 `Character classification <#xs16.2>`__
16.2.1 `Subranges <#xs16.2.1>`__
16.2.2 `Unicode general categories <#xs16.2.2>`__
16.3 `Case conversion <#xs16.3>`__
16.4 `Single digit characters <#xs16.4>`__
16.5 `Numeric representations <#xs16.5>`__
16.6 `String representations <#xs16.6>`__
17 `Data.Complex <#xs17>`__
17.1 `Rectangular form <#xs17.1>`__
17.2 `Polar form <#xs17.2>`__
17.3 `Conjugate <#xs17.3>`__
17.4 `Specification <#xs17.4>`__
18 `Data.Int <#xs18>`__
18.1 `Signed integer types <#xs18.1>`__
19 `Data.Ix <#xs19>`__
19.1 `The Ix class <#xs19.1>`__
19.2 `Deriving Instances of Ix <#xs19.2>`__
20 `Data.List <#xs20>`__
20.1 `Basic functions <#xs20.1>`__
20.2 `List transformations <#xs20.2>`__
20.3 `Reducing lists (folds) <#xs20.3>`__
20.3.1 `Special folds <#xs20.3.1>`__
20.4 `Building lists <#xs20.4>`__
20.4.1 `Scans <#xs20.4.1>`__
20.4.2 `Accumulating maps <#xs20.4.2>`__
20.4.3 `Infinite lists <#xs20.4.3>`__
20.4.4 `Unfolding <#xs20.4.4>`__
20.5 `Sublists <#xs20.5>`__
20.5.1 `Extracting sublists <#xs20.5.1>`__
20.5.2 `Predicates <#xs20.5.2>`__
20.6 `Searching lists <#xs20.6>`__
20.6.1 `Searching by equality <#xs20.6.1>`__
20.6.2 `Searching with a predicate <#xs20.6.2>`__
20.7 `Indexing lists <#xs20.7>`__
20.8 `Zipping and unzipping lists <#xs20.8>`__
20.9 `Special lists <#xs20.9>`__
20.9.1 `Functions on strings <#xs20.9.1>`__
20.9.2 `”Set” operations <#xs20.9.2>`__
20.9.3 `Ordered lists <#xs20.9.3>`__
20.10 `Generalized functions <#xs20.10>`__
20.10.1 `The ”By” operations <#xs20.10.1>`__
20.10.1.1 `User-supplied equality (replacing an Eq context) <#xs20.10.1.1>`__
20.10.1.2 `User-supplied comparison (replacing an Ord context) <#xs20.10.1.2>`__
20.10.2 `The ”generic” operations <#xs20.10.2>`__
21 `Data.Maybe <#xs21>`__
21.1 `The Maybe type and operations <#xs21.1>`__
21.2 `Specification <#xs21.2>`__
22 `Data.Ratio <#xs22>`__
22.1 `Specification <#xs22.1>`__
23 `Data.Word <#xs23>`__
23.1 `Unsigned integral types <#xs23.1>`__
24 `Foreign <#xs24>`__
25 `Foreign.C <#xs25>`__
26 `Foreign.C.Error <#xs26>`__
26.1 `Haskell representations of errno values <#xs26.1>`__
26.1.1 `Common errno symbols <#xs26.1.1>`__
26.1.2 `Errno functions <#xs26.1.2>`__
26.1.3 `Guards for IO operations that may fail <#xs26.1.3>`__
27 `Foreign.C.String <#xs27>`__
27.1 `C strings <#xs27.1>`__
27.1.1 `Using a locale-dependent encoding <#xs27.1.1>`__
27.1.2 `Using 8-bit characters <#xs27.1.2>`__
27.2 `C wide strings <#xs27.2>`__
28 `Foreign.C.Types <#xs28>`__
28.1 `Representations of C types <#xs28.1>`__
28.1.1 `Integral types <#xs28.1.1>`__
28.1.2 `Numeric types <#xs28.1.2>`__
28.1.3 `Floating types <#xs28.1.3>`__
28.1.4 `Other types <#xs28.1.4>`__
29 `Foreign.ForeignPtr <#xs29>`__
29.1 `Finalised data pointers <#xs29.1>`__
29.1.1 `Basic operations <#xs29.1.1>`__
29.1.2 `Low-level operations <#xs29.1.2>`__
29.1.3 `Allocating managed memory <#xs29.1.3>`__
30 `Foreign.Marshal <#xs30>`__
31 `Foreign.Marshal.Alloc <#xs31>`__
31.1 `Memory allocation <#xs31.1>`__
31.1.1 `Local allocation <#xs31.1.1>`__
31.1.2 `Dynamic allocation <#xs31.1.2>`__
32 `Foreign.Marshal.Array <#xs32>`__
32.1 `Marshalling arrays <#xs32.1>`__
32.1.1 `Allocation <#xs32.1.1>`__
32.1.2 `Marshalling <#xs32.1.2>`__
32.1.3 `Combined allocation and marshalling <#xs32.1.3>`__
32.1.4 `Copying <#xs32.1.4>`__
32.1.5 `Finding the length <#xs32.1.5>`__
32.1.6 `Indexing <#xs32.1.6>`__
33 `Foreign.Marshal.Error <#xs33>`__
34 `Foreign.Marshal.Utils <#xs34>`__
34.1 `General marshalling utilities <#xs34.1>`__
34.1.1 `Combined allocation and marshalling <#xs34.1.1>`__
34.1.2 `Marshalling of Boolean values (non-zero corresponds to True) <#xs34.1.2>`__
34.1.3 `Marshalling of Maybe values <#xs34.1.3>`__
34.1.4 `Marshalling lists of storable objects <#xs34.1.4>`__
34.1.5 `Haskellish interface to memcpy and memmove <#xs34.1.5>`__
35 `Foreign.Ptr <#xs35>`__
35.1 `Data pointers <#xs35.1>`__
35.2 `Function pointers <#xs35.2>`__
35.3 `Integral types with lossless conversion to and from pointers <#xs35.3>`__
36 `Foreign.StablePtr <#xs36>`__
36.1 `Stable references to Haskell values <#xs36.1>`__
36.1.1 `The C-side interface <#xs36.1.1>`__
37 `Foreign.Storable <#xs37>`__
38 `Numeric <#xs38>`__
38.1 `Showing <#xs38.1>`__
38.2 `Reading <#xs38.2>`__
38.3 `Miscellaneous <#xs38.3>`__
39 `System.Environment <#xs39>`__
40 `System.Exit <#xs40>`__
41 `System.IO <#xs41>`__
41.1 `The IO monad <#xs41.1>`__
41.2 `Files and handles <#xs41.2>`__
41.2.1 `Standard handles <#xs41.2.1>`__
41.3 `Opening and closing files <#xs41.3>`__
41.3.1 `Opening files <#xs41.3.1>`__
41.3.2 `Closing files <#xs41.3.2>`__
41.3.3 `Special cases <#xs41.3.3>`__
41.3.4 `File locking <#xs41.3.4>`__
41.4 `Operations on handles <#xs41.4>`__
41.4.1 `Determining and changing the size of a file <#xs41.4.1>`__
41.4.2 `Detecting the end of input <#xs41.4.2>`__
41.4.3 `Buffering operations <#xs41.4.3>`__
41.4.4 `Repositioning handles <#xs41.4.4>`__
41.4.5 `Handle properties <#xs41.4.5>`__
41.4.6 `Terminal operations <#xs41.4.6>`__
41.4.7 `Showing handle state <#xs41.4.7>`__
41.5 `Text input and output <#xs41.5>`__
41.5.1 `Text input <#xs41.5.1>`__
41.5.2 `Text output <#xs41.5.2>`__
41.5.3 `Special cases for standard input and output <#xs41.5.3>`__
42 `System.IO.Error <#xs42>`__
42.1 `I/O errors <#xs42.1>`__
42.1.1 `Classifying I/O errors <#xs42.1.1>`__
42.1.2 `Attributes of I/O errors <#xs42.1.2>`__
42.2 `Types of I/O error <#xs42.2>`__
42.3 `Throwing and catching I/O errors <#xs42.3>`__
.. _xs02:
Preface
-------
.. container:: quote
“Some half dozen persons have written technically on combinatory
logic, and most of these, including ourselves, have published
something erroneous. Since some of our fellow sinners are among the
most careful and competent logicians on the contemporary scene, we
regard this as evidence that the subject is refractory. Thus fullness
of exposition is necessary for accuracy; and excessive condensation
would be false economy here, even more than it is ordinarily.”
.. container:: flushright
| Haskell B. Curry and Robert Feys
| in the Preface to Combinatory Logic
[`3 <#Xcurry&feys:book>`__], May 31, 1956
In September of 1987 a meeting was held at the conference on Functional
Programming Languages and Computer Architecture (FPCA ’87) in Portland,
Oregon, to discuss an unfortunate situation in the functional
programming community: there had come into being more than a dozen
non-strict, purely functional programming languages, all similar in
expressive power and semantic underpinnings. There was a strong
consensus at this meeting that more widespread use of this class of
functional languages was being hampered by the lack of a common
language. It was decided that a committee should be formed to design
such a language, providing faster communication of new ideas, a stable
foundation for real applications development, and a vehicle through
which others would be encouraged to use functional languages. This
document describes the result of that (and subsequent) committee’s
efforts: a purely functional programming language called Haskell, named
after the logician Haskell B. Curry whose work provides the logical
basis for much of ours.
.. _xs03:
Goals
~~~~~
The committee’s primary goal was to design a language that satisfied
these constraints:
#. It should be suitable for teaching, research, and applications,
including building large systems.
#. It should be completely described via the publication of a formal
syntax and semantics.
#. It should be freely available. Anyone should be permitted to
implement the language and distribute it to whomever they please.
#. It should be based on ideas that enjoy a wide consensus.
#. It should reduce unnecessary diversity in functional programming
languages.
.. _xs04:
Haskell 2010: language and libraries
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The committee intended that Haskell would serve as a basis for future
research in language design, and hoped that extensions or variants of
the language would appear, incorporating experimental features.
Haskell has indeed evolved continuously since its original publication.
By the middle of 1997, there had been five versions of the language
design (from Haskell 1.0 – 1.4). At the 1997 Haskell Workshop in
Amsterdam, it was decided that a stable variant of Haskell was needed;
this became “Haskell 98” and was published in February 1999. The fixing
of minor bugs led to the Revised Haskell 98 Report in 2002.
At the 2005 Haskell Workshop, the consensus was that so many extensions
to the official language were widely used (and supported by multiple
implementations), that it was worthwhile to define another iteration of
the language standard, essentially to codify (and legitimise) the status
quo.
The Haskell Prime effort was thus conceived as a relatively conservative
extension of Haskell 98, taking on board new features only where they
were well understood and widely agreed upon. It too was intended to be a
“stable” language, yet reflecting the considerable progress in research
on language design in recent years.
After several years exploring the design space, it was decided that a
single monolithic revision of the language was too large a task, and the
best way to make progress was to evolve the language in small
incremental steps, each revision integrating only a small number of
well-understood extensions and changes. Haskell 2010 is the first
revision to be created in this way, and new revisions are expected once
per year.
.. _xs05:
Extensions to Haskell 98
~~~~~~~~~~~~~~~~~~~~~~~~
The most significant language changes in Haskell 2010 relative to
Haskell 98 are listed here.
New language features:
- A Foreign Function Interface (FFI).
- Hierarchical module names, e.g. Data.Bool.
- Pattern guards.
Removed language features:
- The (n + k) pattern syntax.
.. _xs06:
Haskell Resources
~~~~~~~~~~~~~~~~~
The Haskell web site `http://haskell.org <http://haskell.org>`__ gives
access to many useful resources, including:
- Online versions of the language and library definitions.
- Tutorial material on Haskell.
- Details of the Haskell mailing list.
- Implementations of Haskell.
- Contributed Haskell tools and libraries.
- Applications of Haskell.
- User-contributed wiki pages.
- News and events in the Haskell community.
You are welcome to comment on, suggest improvements to, and criticise
the language or its presentation in the report, via the Haskell mailing
list, or the Haskell wiki.
.. _xs07:
Building the language
~~~~~~~~~~~~~~~~~~~~~
Haskell was created, and continues to be sustained, by an active
community of researchers and application programmers. Those who served
on the Language and Library committees, in particular, devoted a huge
amount of time and energy to the language. Here they are, with their
affiliation(s) for the relevant period:
.. container:: center
| Arvind (MIT)
| Lennart Augustsson (Chalmers University)
| Dave Barton (Mitre Corp)
| Brian Boutel (Victoria University of Wellington)
| Warren Burton (Simon Fraser University)
| Manuel M T Chakravarty (University of New South Wales)
| Duncan Coutts (Well-Typed LLP)
| Jon Fairbairn (University of Cambridge)
| Joseph Fasel (Los Alamos National Laboratory)
| John Goerzen
| Andy Gordon (University of Cambridge)
| Maria Guzman (Yale University)
| Kevin Hammond [editor] (University of Glasgow)
| Bastiaan Heeren (Utrecht University)
| Ralf Hinze (University of Bonn)
| Paul Hudak [editor] (Yale University)
| John Hughes [editor] (University of Glasgow; Chalmers University)
| Thomas Johnsson (Chalmers University)
| Isaac Jones (Galois, inc.)
| Mark Jones (Yale University, University of Nottingham, Oregon
Graduate Institute)
| Dick Kieburtz (Oregon Graduate Institute)
| John Launchbury (University of Glasgow; Oregon Graduate Institute;
Galois, inc.)
| Andres Löh (Utrecht University)
| Ian Lynagh (Well-Typed LLP)
| Simon Marlow [editor] (Microsoft Research)
| John Meacham
| Erik Meijer (Utrecht University)
| Ravi Nanavati (Bluespec, inc.)
| Rishiyur Nikhil (MIT)
| Henrik Nilsson (University of Nottingham)
| Ross Paterson (City University, London)
| John Peterson [editor] (Yale University)
| Simon Peyton Jones [editor] (University of Glasgow; Microsoft
Research Ltd)
| Mike Reeve (Imperial College)
| Alastair Reid (University of Glasgow)
| Colin Runciman (University of York)
| Don Stewart (Galois, inc.)
| Martin Sulzmann (Informatik Consulting Systems AG)
| Audrey Tang
| Simon Thompson (University of Kent)
| Philip Wadler [editor] (University of Glasgow)
| Malcolm Wallace (University of York)
| Stephanie Weirich (University of Pennsylvania)
| David Wise (Indiana University)
| Jonathan Young (Yale University)
Those marked [editor] served as the co-ordinating editor for one or more
revisions of the language.
In addition, dozens of other people made helpful contributions, some
small but many substantial. They are as follows: Hans Aberg, Kris Aerts,
Sten Anderson, Richard Bird, Tom Blenko, Stephen Blott, Duke Briscoe,
Paul Callaghan, Magnus Carlsson, Mark Carroll, Franklin Chen, Olaf
Chitil, Chris Clack, Guy Cousineau, Tony Davie, Craig Dickson, Chris
Dornan, Laura Dutton, Chris Fasel, Pat Fasel, Sigbjorn Finne, Michael
Fryers, Peter Gammie, Andy Gill, Mike Gunter, Cordy Hall, Mark Hall,
Thomas Hallgren, Matt Harden, Klemens Hemm, Fergus Henderson, Dean
Herington, Bob Hiromoto, Nic Holt, Ian Holyer, Randy Hudson, Alexander
Jacobson, Patrik Jansson, Robert Jeschofnik, Orjan Johansen, Simon
B. Jones, Stef Joosten, Mike Joy, Wolfram Kahl, Stefan Kahrs,
Antti-Juhani Kaijanaho, Jerzy Karczmarczuk, Kent Karlsson, Martin D.
Kealey, Richard Kelsey, Siau-Cheng Khoo, Amir Kishon, Feliks Kluzniak,
Jan Kort, Marcin Kowalczyk, Jose Labra, Jeff Lewis, Mark Lillibridge,
Bjorn Lisper, Sandra Loosemore, Pablo Lopez, Olaf Lubeck, Christian
Maeder, Ketil Malde, Michael Marte, Jim Mattson, John Meacham, Sergey
Mechveliani, Gary Memovich, Randy Michelsen, Rick Mohr, Andy Moran,
Graeme Moss, Arthur Norman, Nick North, Chris Okasaki, Bjarte M.
Østvold, Paul Otto, Sven Panne, Dave Parrott, Larne Pekowsky, Rinus
Plasmeijer, Ian Poole, Stephen Price, John Robson, Andreas Rossberg,
George Russell, Patrick Sansom, Michael Schneider, Felix Schroeter,
Julian Seward, Nimish Shah, Christian Sievers, Libor Skarvada, Jan
Skibinski, Lauren Smith, Raman Sundaresh, Josef Svenningsson, Ken
Takusagawa, Wolfgang Thaller, Satish Thatte, Tom Thomson, Tommy Thorn,
Dylan Thurston, Mike Thyer, Mark Tullsen, David Tweed, Pradeep Varma,
Keith Wansbrough, Tony Warnock, Michael Webber, Carl Witty, Stuart Wray,
and Bonnie Yantis.
Finally, aside from the important foundational work laid by Church,
Rosser, Curry, and others on the lambda calculus, it is right to
acknowledge the influence of many noteworthy programming languages
developed over the years. Although it is difficult to pinpoint the
origin of many ideas, the following languages were particularly
influential: Lisp (and its modern-day incarnations Common Lisp and
Scheme); Landin’s ISWIM; APL; Backus’s FP
[`1 <#Xback78>`__]; ML and Standard ML; Hope and
Hope\ :sup:`+`; Clean; Id; Gofer; Sisal; and Turner’s series of
languages culminating in Miranda\ `1 <#fn1x0>`__ . Without
these forerunners Haskell would not have been possible.
| Simon Marlow
| Cambridge, April 2010
Part I The Haskell 2010 Language
=================================
.. container:: chapterTOCS
* 1 `Introduction <#xs1>`__
* 1.1 `Program Structure <#xs1.1>`__
* 1.2 `The Haskell Kernel <#xs1.2>`__
* 1.3 `Values and Types <#xs1.3>`__
* 1.4 `Namespaces <#xs1.4>`__
* 2 `Lexical Structure <#xs2>`__
* 2.1 `Notational Conventions <#xs2.1>`__
* 2.2 `Lexical Program Structure <#xs2.2>`__
* 2.3 `Comments <#xs2.3>`__
* 2.4 `Identifiers and Operators <#xs2.4>`__
* 2.5 `Numeric Literals <#xs2.5>`__
* 2.6 `Character and String Literals <#xs2.6>`__
* 2.7 `Layout <#xs2.7>`__
* 3 `Expressions <#xs3>`__
* 3.1 `Errors <#xs3.1>`__
* 3.2 `Variables, Constructors, Operators, and Literals <#xs3.2>`__
* 3.3 `Curried Applications and Lambda Abstractions <#xs3.3>`__
* 3.4 `Operator Applications <#xs3.4>`__
* 3.5 `Sections <#xs3.5>`__
* 3.6 `Conditionals <#xs3.6>`__
* 3.7 `Lists <#xs3.7>`__
* 3.8 `Tuples <#xs3.8>`__
* 3.9 `Unit Expressions and Parenthesized Expressions <#xs3.9>`__
* 3.10 `Arithmetic Sequences <#xs3.10>`__
* 3.11 `List Comprehensions <#xs3.11>`__
* 3.12 `Let Expressions <#xs3.12>`__
* 3.13 `Case Expressions <#xs3.13>`__
* 3.14 `Do Expressions <#xs3.14>`__
* 3.15 `Datatypes with Field Labels <#xs3.15>`__
* 3.16 `Expression Type-Signatures <#xs3.16>`__
* 3.17 `Pattern Matching <#xs3.17>`__
* 4 `Declarations and Bindings <#xs4>`__
* 4.1 `Overview of Types and Classes <#xs4.1>`__
* 4.2 `User-Defined Datatypes <#xs4.2>`__
* 4.3 `Type Classes and Overloading <#xs4.3>`__
* 4.4 `Nested Declarations <#xs4.4>`__
* 4.5 `Static Semantics of Function and Pattern Bindings <#xs4.5>`__
* 4.6 `Kind Inference <#xs4.6>`__
* 5 `Modules <#xs5>`__
* 5.1 `Module Structure <#xs5.1>`__
* 5.2 `Export Lists <#xs5.2>`__
* 5.3 `Import Declarations <#xs5.3>`__
* 5.4 `Importing and Exporting Instance Declarations <#xs5.4>`__
* 5.5 `Name Clashes and Closure <#xs5.5>`__
* 5.6 `Standard Prelude <#xs5.6>`__
* 5.7 `Separate Compilation <#xs5.7>`__
* 5.8 `Abstract Datatypes <#xs5.8>`__
* 6 `Predefined Types and Classes <#xs6>`__
* 6.1 `Standard Haskell Types <#xs6.1>`__
* 6.2 `Strict Evaluation <#xs6.2>`__
* 6.3 `Standard Haskell Classes <#xs6.3>`__
* 6.4 `Numbers <#xs6.4>`__
* 7 `Basic Input/Output <#xs7>`__
* 7.1 `Standard I/O Functions <#xs7.1>`__
* 7.2 `Sequencing I/O Operations <#xs7.2>`__
* 7.3 `Exception Handling in the I/O Monad <#xs7.3>`__
* 8 `Foreign Function Interface <#xs8>`__
* 8.1 `Foreign Languages <#xs8.1>`__
* 8.2 `Contexts <#xs8.2>`__
* 8.3 `Lexical Structure <#xs8.3>`__
* 8.4 `Foreign Declarations <#xs8.4>`__
* 8.5 `Specification of External Entities <#xs8.5>`__
* 8.6 `Marshalling <#xs8.6>`__
* 8.7 `The External C Interface <#xs8.7>`__
* 9 `Standard Prelude <#xs9>`__
* 9.1 `Prelude PreludeList <#xs9.1>`__
* 9.2 `Prelude PreludeText <#xs9.2>`__
* 9.3 `Prelude PreludeIO <#xs9.3>`__
* 10 `Syntax Reference <#xs10>`__
* 10.1 `Notational Conventions <#xs10.1>`__
* 10.2 `Lexical Syntax <#xs10.2>`__
* 10.3 `Layout <#xs10.3>`__
* 10.4 `Literate comments <#xs10.4>`__
* 10.5 `Context-Free Syntax <#xs10.5>`__
* 10.6 `Fixity Resolution <#xs10.6>`__
* 11 `Specification of Derived Instances <#xs11>`__
* 11.1 `Derived instances of Eq and Ord <#xs11.1>`__
* 11.2 `Derived instances of Enum <#xs11.2>`__
* 11.3 `Derived instances of Bounded <#xs11.3>`__
* 11.4 `Derived instances of Read and Show <#xs11.4>`__
* 11.5 `An Example <#xs11.5>`__
* 12 `Compiler Pragmas <#xs12>`__
* 12.1 `Inlining <#xs12.1>`__
* 12.2 `Specialization <#xs12.2>`__
* 12.3 `Language extensions <#xs12.3>`__
.. _xs1:
Chapter 1 Introduction
----------------------
Haskell is a general purpose, purely functional programming language
incorporating many recent innovations in programming language design.
Haskell provides higher-order functions, non-strict semantics, static
polymorphic typing, user-defined algebraic datatypes, pattern-matching,
list comprehensions, a module system, a monadic I/O system, and a rich
set of primitive datatypes, including lists, arrays, arbitrary and fixed
precision integers, and floating-point numbers. Haskell is both the
culmination and solidification of many years of research on non-strict
functional languages.
This report defines the syntax for Haskell programs and an informal
abstract semantics for the meaning of such programs. We leave as
implementation dependent the ways in which Haskell programs are to be
manipulated, interpreted, compiled, etc. This includes such issues as
the nature of programming environments and the error messages returned
for undefined programs (i.e. programs that formally evaluate to ⊥).
.. _xs1.1:
1.1 Program Structure
~~~~~~~~~~~~~~~~~~~~~~
In this section, we describe the abstract syntactic and semantic
structure of Haskell, as well as how it relates to the organization of
the rest of the report.
#. At the topmost level a Haskell program is a set of modules, described
in Chapter `5 <#xs5>`__. Modules provide a way
to control namespaces and to re-use software in large programs.
#. The top level of a module consists of a collection of declarations,
of which there are several kinds, all described in
Chapter `4 <#xs4>`__. Declarations define
things such as ordinary values, datatypes, type classes, and fixity
information.
#. At the next lower level are expressions, described in
Chapter `3 <#xs3>`__. An expression denotes a
value and has a static type; expressions are at the heart of Haskell
programming “in the small.”
#. At the bottom level is Haskell’s lexical structure, defined in
Chapter `2 <#xs2>`__. The lexical structure
captures the concrete representation of Haskell programs in text
files.
This report proceeds bottom-up with respect to Haskell’s syntactic
structure.
The chapters not mentioned above are
Chapter `6 <#xs6>`__, which describes the
standard built-in datatypes and classes in Haskell, and
Chapter `7 <#xs7>`__, which discusses the I/O
facility in Haskell (i.e. how Haskell programs communicate with the
outside world). Also, there are several chapters describing the Prelude,
the concrete syntax, literate programming, the specification of derived
instances, and pragmas supported by most Haskell compilers.
Examples of Haskell program fragments in running text are given in
typewriter font:
.. container:: quote
.. container:: verbatim
:name: verbatim-1
let x = 1
z = x+y
in z+1
“Holes” in program fragments representing arbitrary pieces of Haskell
code are written in italics, as in
if e\ :sub:`1` then e\ :sub:`2` else e\ :sub:`3`. Generally the
italicized names are mnemonic, such as e for expressions, d for
declarations, t for types, etc.
.. _xs1.2:
1.2 The Haskell Kernel
~~~~~~~~~~~~~~~~~~~~~~~
Haskell has adopted many of the convenient syntactic structures that
have become popular in functional programming. In this Report, the
meaning of such syntactic sugar is given by translation into simpler