type Result<'a> =
| Success of 'a
| Failure of string
type ResultBuilder() =
member m.Return a = Success(a)
member m.Bind(r,fn) =
match r with
| Success(a) -> fn a
| Failure(m) -> Failure(m)
module Parser =
let res = ResultBuilder()
let Combine p1 p2 fn =
fun a -> res { let! x = p1 a
let! y = p2 a
return fn(x,y) }
let Combine2 p1 p2 fn =
try
return fn(x,y)
with
| ex -> Failure(ex.Message) }