Module Foldable.Law
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
Signature
val fold_right : ('a -> 'b -> 'b) -> 'b -> 'a F.t -> bool
fold_right f init t
istrue
whenF.fold_right ~f ~init t = (F.fold_map ~m ~f t) init
where
init
has typea
andm
is the Endo monoid over functions of typea -> a
.
val fold_left : ('a -> 'a -> 'a) -> 'a -> 'a F.t -> bool
fold_left f init t
istrue
whenF.fold_right ~f ~init t = (F.fold_map ~m ~f:(Fun.flip f) t) init
where
init
has typea
andm
is the Dual of the Endo monoid over functions of typea -> a
.
val fold : (module Monoid.S with type t = 'a) -> 'a F.t -> bool
fold (module M) t
istrue
whenF.fold (module M) t = F.fold_map ~m:(module M) ~f:Fun.id t
val length : 'a F.t -> bool
length t
istrue
whenF.length t = F.fold_map ~m ~f:(Fun.const 1) t
where
m
isMonoid.Int.Sum
.