Travesty is a library for defining containers with monadic and otherwise 'exotic' traversals, inspired by Haskell's Traversable and related typeclasses. It sits on top of Jane Street's Core library ecosystem.
As well as monadic traversals, Travesty includes various other extensions on top of Core. These focus on making a more 'purely functional', Haskell-esque style of programming easier, though with a focus on pragmatism over mathematical purity.
Travesty contains module signatures, functors, and extensions for dealing with various kinds of traversability:
- Mappable: mapping (in Haskell, functors);
- Traversable: monadic traversal (in Haskell, traversable functors);
- Bi_mappable: mapping on two types over the same container (in Haskell, bifunctors);
- Filter_mappable: mapping that can discard elements (similar to the filtrable Haskell library).
Haskell's foldable functors already exist in Base as Container.
Travesty also contains implementations of state monads (State) and transformers (State_transform). We use these to implement fold-mapping and folding on top of Traversable, but expose them for general consumption.
Travesty also contains extensions to various module signatures, as well as to Base and Core_kernel container and monad modules. We keep the latter in sub-libraries of
These are in the
Travesty library, and always have the suffix
exts. Some Travesty signatures pull them in automatically.
- Containers (Container_exts)
- Monads (Monad_exts)
These are in the Travesty_base_exts library (expanding the
Base versions) and the Travesty_core_kernel_exts library (expanding the
Core_kernel versions). Each usually has the same name as the module it extends (except `Alist`), but doesn't re-export that module. The intended mode of use is:
(* Base *) open Base module Tx = Travesty_base_Exts (* Core_kernel *) open Core_kernel module Tx = Travesty_core_kernel_exts let example (foo : ('k, 'v) List.Assoc.t) = Tx.Alist.bi_map ~left:foo ~right:bar foo
Tuple2: pairs/2-tuples (Base, Core_kernel)
Alist: associative lists (Base, Core_kernel)
Or_error: error monad (Base, Core_kernel)
Fn: function combinators (Base, Core_kernel)
List: lists (Base, Core_kernel)
Option: options (Base, Core_kernel)
As well as expanding various
Travesty features some of its own. These have various traversal and mapping features built in, but aren't necessarily optimised for heavy-duty use.
Each is in the Travesty_containers subpackage (in Dune, use
Other similar libraries
- The BAP monads library also contains implementations of monadic traversals, as well as several of
Travesty's other extensions.
Projects depending on Travesty
- act, a toolbox for automatic compiler testing.