package popper

  1. Overview
  2. Docs

Module Popper.SampleSource

Types

Sourcetype 'a t

A value of type 'a t is a parser that when run with an Input.t value, produces some output containing a value of type 'a.

Basic Combinators

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map f s creates a sample that when run maps its output value using the function f.

Sourceval return : 'a -> 'a t

return x is a sample that does not read any input and always produces a value containing x.

Sourceval bind : 'a t -> ('a -> 'b t) -> 'b t

bind s f is a sample that when run, first executes s on the given input, then applies its output value to f in order to produe a new sample that is run on the remaining input. This is the monadic operator for sequencing sample operations.

Sourceval both : 'a t -> 'b t -> ('a * 'b) t

both s1 s2 is a sample that when run executes s1 followed by s2 and combines their result.

Sourceval size : int t

size returns the current max-size argument.

Sourceval sized : (int -> 'a t) -> 'a t

sized f lifts the function f that depend on a size argument to a sample.

Sourceval resize : int -> 'a t -> 'a t

resize n s creates a sample that when run fixes the size parameter to n.

Sourceval one_of : 'a t list -> 'a t

one_of ss is a sample that selects on of the given sample from the list ss.

Sourceval one_value_of : 'a list -> 'a t

one_vlaue_of xs same as one_of but lifts all values to samples using return.

Sourceval choose : (float * 'a t) list -> 'a t

choose fss chooses one sample from the list with a probability corresponding to the relative weight, as specified by the weight and sample pairs in fss.

Sourceval delayed : (unit -> 'a t) -> 'a t

delayed f is sample that delays the production of the sample using f until run

Sourceval sequence : 'a t list -> 'a list t

sequence ss is a sample that runs each sample in ss and combines their results in a list.

Primitives

Sourceval unit : unit t

unit is a sample that produce a unit value without consuming any input.

Sourceval int : int t

int is a sample that produces int values.

Sourceval int32 : int32 t

int32 is a sample that produces int32 values.

Sourceval int64 : int64 t

int64 is a sample that produces int64 values.

Sourceval char : char t

char is a sample that produces char values.

Sourceval float : float t

float is a sample that produces float values.

Sourceval bool : bool t

bool is a sample that produces bool values.

Sourceval fn : 'a t -> ('b -> 'a) t

fn s is a sample that produces a function value.

Sourceval string : string t

char is a sample that produces char values.

Combinators for higher-kinded types

Sourceval option : 'a t -> 'a option t

option s is a sample that either produces a value None or a value of Some using s.

Sourceval result : ok:'a t -> error:'b t -> ('a, 'b) result t

result ~ok ~error is a sample that produces a result value, either using the ok sample, or an error using the error sample.

Sourceval list : 'a t -> 'a list t

list s is a sample that produces a list using the give s. The size of the list is not determined but is influenced by the implicit size parameter.

Debugging combinators

Sourceval log_key_value : string -> string -> unit t

log_key_value key value is a sample that when run logs the given key and value pair without consuming any input.

Sourceval with_log : string -> (Format.formatter -> 'a -> unit) -> 'a t -> 'a t

with_log key pp s enhances the given sample s so as to also log its result using the key and printer pp for producing a string value.

Sourceval with_consumed : 'a t -> ('a * Consumed.t) t

with_consumed s is a sample produces a pair of a value using s and its consumed data. This would only be used for debugging purposes.

Sourceval tag_name : string -> 'a t -> 'a t

tag_name name s is a sample that when run, applies s but tags its consumed input with the given name. Mostly useful for debuggin.

Sourcemodule Syntax : sig ... end
Sourcemodule Int : sig ... end
Sourcemodule Float : sig ... end
Sourcemodule List : sig ... end
Sourcemodule Array : sig ... end
Sourcemodule String : sig ... end
Sourcemodule Tuple : sig ... end