package alg_structs

  1. Overview
  2. Docs

Law notes the laws that should be obeyed by any instantiation of Foldable in the form of predicates that should hold true for any arguments of the appropriate type.

You can use the alg_structs_qcheck package to generate property based tests of these laws for new modules satisfying this interface.

  • parameter F

    An implementation of Foldable

Parameters

module F : S

Signature

val fold_right : ('a -> 'b -> 'b) -> 'b -> 'a F.t -> bool

fold_right f init t is true when

F.fold_right ~f ~init t = (F.fold_map ~m ~f t) init

where init has type a and m is the Endo monoid over functions of type a -> a.

val fold_left : ('a -> 'a -> 'a) -> 'a -> 'a F.t -> bool

fold_left f init t is true when

F.fold_right ~f ~init t = (F.fold_map ~m ~f:(Fun.flip f) t) init

where init has type a and m is the Dual of the Endo monoid over functions of type a -> a.

val fold : (module Monoid.S with type t = 'a) -> 'a F.t -> bool

fold (module M) t is true when

F.fold (module M) t = F.fold_map ~m:(module M) ~f:Fun.id t
val length : 'a F.t -> bool

length t is true when

F.length t = F.fold_map ~m ~f:(Fun.const 1) t

where m is Monoid.Int.Sum.