package parsite

  1. Overview
  2. Docs

Module Types.PResultMSource

There's also the PResultM monad which has a return function that wrapps its input in a Win constructor, and the bind (>>=) operator which applies a function to a p_result value if that value is a Win value.

Also includes a fail function that returns an error message, and (=<<) infix function to handle any Lose cases.

It's a basic monad but it helped string a few things along easier.

Sourceval return : ('b * 'a) -> ('a, 'b) p_result

Takes in a tuple of type ('b * 'a) and returns it wrapped in a Win constructor

  return (b, a) = Win (b, a)
Sourceval (>>=) : ('a, 'b) p_result -> (('b * 'a) -> ('a, 'c) p_result) -> ('a, 'c) p_result

Bind function, takes in a p_result and if the result is a Win, the function is applied to the tuple inside. If the result is a Lose, the result is just returned without any change.

  Win (b, a) >>= fun (a1, a2) -> 
  (a1 = b) && (a2 = a)
Sourceval fail : string -> ('a, 'b) p_result

Fail function that takes in a string and evaluates to Lose with that string as a fail message

  fail a -> Lose a
Sourceval (=<<) : ('a, 'b) p_result -> (string -> ('a, 'b) p_result) -> ('a, 'b) p_result

A sort of reverse bind of sorts. Takes in a p_result and a function, and it applies the function to the string inside the result if the result is a Lose.

  Lose a =<< fun a1 -> 
  (a = a1)