From 6ad975083e3a821ebcee591717fc4a3be3cea0dc Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 18 Apr 2016 00:17:20 +0100 Subject: [PATCH] make it typecheck --- Posts/OCaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Posts/OCaml b/Posts/OCaml index 092cb92..0c1fd54 100644 --- a/Posts/OCaml +++ b/Posts/OCaml @@ -54,7 +54,7 @@ pattern match to handle the different cases. The compiler checks whether your p functional programming is that you can pass functions to other functions (*higher-order functions*). Also, *recursion* is fundamental for functional programming: a function calls itself -- combined with a variant type (such as -`type list = Nil | Cons of a * a list`) it is trivial to show termination. +`type 'a list = Nil | Cons of 'a * 'a list`) it is trivial to show termination. *Side effects* make the program interesting, because they communicate with other systems or humans. Side effects should be isolated and @@ -73,7 +73,7 @@ OCaml has a object and class system, which I do not use. OCaml also contains exceptions (and annoyingly the standard library (e.g. `List.find`) is full of them), which I avoid as well. Libraries should not expose any exception (apart from out of memory, a really exceptional situation). If your code might end up in an error state (common for parsers which process input -from the network), return a variant type as value (`type result = Ok of 'a | Error of 'b`). +from the network), return a variant type as value (`type ('a, 'b) result = Ok of 'a | Error of 'b`). That way, the caller has to handle both the success and failure case explicitly.