bookmark

Syntax extension for Monads in OCaml


Description

Syntax extension for Monads in Ocaml Jacques Carette, Lydia E. van Dijk and Oleg Kiselyov This Camlp4 extension provides some syntactic sugar to beautify monadic expressions. Example: A simple but realistic example of the use of a list monad looks like this bind [1; 2; 3] (fun a -> bind [3; 4; 5] (fun b -> return (a + b))) where we assume the appropriate definitions of the functions "bind" and "return". With the help of "pa_monad" this can be written as perform a <-- [1; 2; 3]; b <-- [3; 4; 5]; return (a + b) which is much clearer and thus easier to understand and maintain. By the way, the expression evaluates to [4; 5; 6; 5; 6; 7; 6; 7; 8] the sum of each pair of values of the input list

Preview

Tags

Users

  • @draganigajic

Comments and Reviews