Skip to content

Instantly share code, notes, and snippets.

@keleshev
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keleshev/16097f71e9edaa08abcf to your computer and use it in GitHub Desktop.
Save keleshev/16097f71e9edaa08abcf to your computer and use it in GitHub Desktop.
include (struct
type 'a t = 'a * string list
exception FatalWarning of string list
let to_exn: 'a t -> 'a = function
| value, [] -> value
| value, warnings -> raise (FatalWarning warnings)
let map f (value, warnings) = f value, warnings
let of_option replacement warning = function
| Some value -> value, []
| None -> replacement, [warning]
let ok value = value, []
let warned value warning = value, [warning]
let create ?(warnings=[]) value = value, warnings
end: sig
type 'a t
exception FatalWarning of string list
val to_exn: 'a t -> 'a
val map: ('a -> 'b) -> 'a t -> 'b t
val of_option: 'a -> string -> 'a option -> 'a t
val ok: 'a -> 'a t
val warned: 'a -> string -> 'a t
val create: ?warnings:string list -> 'a -> 'a t
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment