My agentic slop goes here. Not intended for anyone else!
1(** Error handling for geographic coordinates *)
2
3type t =
4 | Invalid_latitude of float
5 | Invalid_longitude of float
6 | Parse_error of string
7 | Invalid_format of string
8 | Invalid_hemisphere of string
9
10exception Coordinate_error of t
11
12let to_string = function
13 | Invalid_latitude f -> Printf.sprintf "Invalid latitude: %.6f (must be between -90 and 90)" f
14 | Invalid_longitude f -> Printf.sprintf "Invalid longitude: %.6f" f
15 | Parse_error s -> Printf.sprintf "Parse error: %s" s
16 | Invalid_format s -> Printf.sprintf "Invalid format: %s" s
17 | Invalid_hemisphere s -> Printf.sprintf "Invalid hemisphere: %s" s
18
19let catch f x =
20 try Ok (f x)
21 with Coordinate_error e -> Error e
22
23let catch_exn f x =
24 try Some (f x)
25 with Coordinate_error _ -> None
26
27let unwrap = function
28 | Ok x -> x
29 | Error e -> raise (Coordinate_error e)
30
31let unwrap_or default = function
32 | Ok x -> x
33 | Error _ -> default