Learn Programming with OCaml

by Sylvain Conchon and Jean-Christophe Filliâtre

Below you will find the source code of all the programs from the book. Click on the program title to have a look at it; click in the download column to download it.

Download everything (ZIP file)

program page download
1. Leap Years 8 p1.ml
2. The Monte-Carlo Method 18 p2.ml
3. Drawing a Cardioid 28 p3.ml
4. The Mandelbrot Set 35 p4.ml
5. Sieve of Eratosthenes 41 p5.ml
6. Drawing a Curve 50 p6.ml
7. Copying a File 60 p7.ml
8. Reversing the Order of Lines in a Text 67 p8.ml
9. Converting Integers from an Arbitrary Base 76 p9.ml
10. Breakout without Bricks (1/2) 86 p10.ml
11. Breakout without Bricks (2/2) 90 p11.ml
12. Interface for Module draw 93 p12.ml
13. Logo Turtle 98 p13.ml
14. Playing a Musical Score 105 p14.ml
15. Quadtrees 114 p15.ml
16. Solving the N-Queens Problem 121 p16.ml
17. Minimal Signature for Resizeable Arrays 166 p17.ml
18. Resizeable Arrays 168 p18.ml
19. Minimal Signature of Bit Vectors 172 p19.ml
20. Creation of a Bit Vector 174 p20.ml
21. Reading and Writing in a Bit Vector 175 p21.ml
22. Operations and and not on bit vectors 176 p22.ml
23. Iteration Over the Set Bits of a Bit Vector 178 p23.ml
24. Generic String Signature 182 p24.ml
25. Signature of Ropes 183 p25.ml
26. Basic Operations on Ropes 185 p26.ml
27. Concatenation of Two Ropes 189 p27.ml
28. Subrope Extraction 192 p28.ml
29. Update Operations on Ropes 193 p29.ml
30. Signature of Persistent Arrays 198 p30.ml
31. Persistent Arrays 202 p31.ml
32. Signature of Persistent Sets 209 p32.ml
33. Signature of Ordered Types 209 p33.ml
34. Binary Search Trees (1/2) 213 p34.ml
35. Binary Search Trees (2/2) 215 p35.ml
36. Balancing an AVL Tree 222 p36.ml
37. Insertion and Removal in an AVL Tree 224 p37.ml
38. Minimal Signature for Persistent Dictionaries 226 p38.ml
39. Searching in an AVL Dictionary 226 p39.ml
40. Signature for Imperative Sets 229 p40.ml
41. Signature Required for the Elements of a Hash Table 230 p41.ml
42. Searching in a Hash Table 232 p42.ml
43. Inserting an Element into a Hash Table 233 p43.ml
44. Deletion from a Hash Table 233 p44.ml
45. Resizing a Hash Table 236 p45.ml
46. Searching in an Associative Hash Table 238 p46.ml
47. Prefix Trees 239 p47.ml
48. Prefix Trees 240 p48.ml
49. Prefix Trees 241 p49.ml
50. Insertion and Removal in a Prefix Tree 244 p50.ml
51. Intersection of Prefix Trees 246 p51.ml
52. Searching in a Prefix Tree 248 p52.ml
53. Searching in a Patricia Tree 251 p53.ml
54. Insertion in a Patricia Tree 253 p54.ml
55. Removing an Element in a Patricia Tree 256 p55.ml
56. Union of Two Patricia Trees 259 p56.ml
57. Minimal signature for imperative queues 268 p57.ml
58. Imperative queues using linked lists 271 p58.ml
59. Minimal signature for persistent queues 273 p59.ml
60. Persistent queues represented by pairs of lists 275 p60.ml
61. Minimal signature for imperative priority queues 277 p61.ml
62. Ordered elements with a default value 278 p62.ml
63. An imperative heap data structure (1/2) 281 p63.ml
64. An imperative heap data structure (2/2) 284 p64.ml
65. Minimal signature for persistent priority queues 286 p65.ml
66. Persistent Priority Queues 288 p66.ml
67. Minimal signature for graphs with integer vertices 298 p67.ml
68. Graphs via adjacency matrices 299 p68.ml
69. Graphs via adjacency lists 303 p69.ml
70. Graphs via adjacency dictionaries 307 p70.ml
71. Signature of the union-find structure 315 p71.ml
72. Union-find Data Structure 316 p72.ml
73. Structure of a zipper on a list 326 p73.ml
74. A zipper structure on a binary tree 330 p74.ml
75. Lexicographic comparison of binary trees 334 p75.ml
76. Cursor structure 335 p76.ml
77. Cursors on list 336 p77.ml
78. Cursors on trees (infix traversal) 337 p78.ml
79. The extended Euclidean algorithm 345 p79.ml
80. Exponentiation by Squaring 346 p80.ml
81. Modular Arithmetic 348 p81.ml
82. Arithmetic modulo m (multiplication and division) 349 p82.ml
83. Matrix Calculus 351 p83.ml
84. Computing Fn via memoization 360 p84.ml
85. Computing Fn via dynamic programming 361 p85.ml
86. Generic memoization operator 364 p86.ml
87. Hash-consing (code) 370 p87.ml
88. Hash-consing (interface) 371 p88.ml
89. Insertion sort on lists 377 p89.ml
90. Insertion sort on arrays 379 p90.ml
91. Quicksort on lists 381 p91.ml
92. Quicksort on arrays 385 p92.ml
93. Merge sort on lists 388 p93.ml
94. Merge sort on arrays 392 p94.ml
95. Minimal signature for imperative priority queues 394 p95.ml
96. Heapsort on lists 395 p96.ml
97. Heapsort on arrays 399 p97.ml
98. Graph Algorithms 414 p98.ml
99. Breadth-First Search 416 p99.ml
100. Depth-First Search 418 p100.ml
101. Shortest path (Dijkstra’s algorithm) 424 p101.ml
102. The Bellman-Ford algorithm 427 p102.ml
103. Minimum spanning tree 431 p103.ml

Back