Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

New apis

nilsbecker edited this page · 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]
Something went wrong with that request. Please try again.