New apis

nilsbecker edited this page Sep 18, 2014 · 8 revisions

#Features provided by Batteries

Combinators

Pipeline Operator (|>)

This operator is commonly used to give code a dataflow structure. Since 4.01 this is included in standard OCaml.

Enum

Everything converts to and from an Enum, an efficient enumeration type.

Instead of a for loop with body f:int -> unit, one can write (1--n) |> iter f.

To convert between a List and a Set, write List.enum lst |> Set.of_enum.

IO

General purpose Input/Output channels

Misc

###Return Same as http://ocaml.janestcapital.com/?q=node/91 but with slightly different names.

Printing Functions

Data structure modules provide a print function that can be used with Printf.printf like this:

Printf.printf "Int is: %a" Int.print 5

This is pretty boring, until you realize that polymorphic containers' print functions are composable:

Printf.printf "Pair: %a, List:%a\n" (Pair.print String.print Float.print) ("abc",3.14) (List.print Int.print) [3;4;5]
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.