Tutorial by Examples

Higher-order functions can be used to implement generic algorithms, giving up the responsibility of providing final details to the user. For instance List.sort expects a comparison function, which allows to implement various ways of sorting. Here we implement case-insensitive sorting of strings: le...
Higher-order functions can be used to ensure that system resources are disposed, even when a treatment raises an exception. The pattern used by with_output_file allows a clean separation of concerns: the higher-order with_output_file functions takes care of managing the system resources bound to fi...
Two useful higher-order functions are the binary application (@@) and reverse-application or "pipe" (|>) operators. Although since 4.01 they're available as primitives, it might still be instructive to define them here: let (|>) x f = f x let (@@) f x = f x Consider the problem ...

Page 1 of 1