package preface
Source file try.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42type 'a t = ('a, exn) Result.t let pure x = Ok x let ok = pure let error exn = Error exn module Functor = Result.Functor (struct type t = exn end) module Invariant = Preface_make.Invariant.From_functor (Functor) module Alt = Result.Alt (struct type t = exn end) module Applicative = Result.Applicative (struct type t = exn end) module Monad = Result.Monad (struct type t = exn end) module Selective = Result.Selective (struct type t = exn end) module Foldable = Result.Foldable (struct type t = exn end) let capture f = try ok (f ()) with exn -> error exn let case f g = function Ok x -> f x | Error exn -> g exn let to_validation = function | Ok x -> Validation.valid x | Error exn -> Validation.invalid (Nonempty_list.create exn) ;; let equal f = Result.equal f Exn.equal let pp pp' = Result.pp pp' Exn.pp