(*Generated by Lem from maybe.lem.*)
 

open Lem_bool
open Lem_basic_classes
open Lem_function

(* ========================================================================== *)
(* Basic stuff                                                                *)
(* ========================================================================== *)

(*type maybe 'a = 
  | Nothing
  | Just of 'a*)


(*val maybeEqual : forall 'a. Eq 'a => maybe 'a -> maybe 'a -> bool*)
(*val maybeEqualBy : forall 'a. ('a -> 'a -> bool) -> maybe 'a -> maybe 'a -> bool*)

(*let maybeEqualBy eq x y = match (x,y) with
  | (Nothing, Nothing) -> true
  | (Nothing, Just _) -> false
  | (Just _, Nothing) -> false
  | (Just x', Just y') -> (eq x' y')
end*)

let instance_Basic_classes_Eq_Maybe_maybe_dict dict_Basic_classes_Eq_a =({

  isEqual_method = (Lem.option_equal  
  dict_Basic_classes_Eq_a.isEqual_method);

  isInequal_method = (fun x y->not ((Lem.option_equal  
  dict_Basic_classes_Eq_a.isEqual_method x y)))})  


let maybeCompare cmp x y = ((match (x,y) with
  | (None, None) -> 0
  | (None, Some _) -> (-1)
  | (Some _, None) -> 1
  | (Some x', Some y') -> cmp x' y'
))

let instance_Basic_classes_SetType_Maybe_maybe_dict dict_Basic_classes_SetType_a =({

  setElemCompare_method = (maybeCompare  
  dict_Basic_classes_SetType_a.setElemCompare_method)})


(* ----------------------- *)
(* maybe                   *)
(* ----------------------- *)

(*val maybe : forall 'a 'b. 'b -> ('a -> 'b) -> maybe 'a -> 'b*)
(*let maybe d f mb = match mb with 
  | Just a -> f a
  | Nothing -> d
end*)

(* ----------------------- *)
(* isJust / isNothing      *)
(* ----------------------- *)

(*val isJust : forall 'a. maybe 'a -> bool*)
(*let isJust mb = match mb with 
  | Just _ -> true
  | Nothing -> false
end*)

(*val isNothing : forall 'a. maybe 'a -> bool*)
(*let isNothing mb = match mb with 
  | Just _ -> false
  | Nothing -> true
end*)

(* ----------------------- *)
(* fromMaybe               *)
(* ----------------------- *)

(*val fromMaybe : forall 'a. 'a -> maybe 'a -> 'a*)
(*let fromMaybe d mb = match mb with
   | Just v  -> v
   | Nothing -> d
end*)

(* ----------------------- *)
(* map                     *)
(* ----------------------- *)

(*val map : forall 'a 'b. ('a -> 'b) -> maybe 'a -> maybe 'b*) 
(*let map f = maybe Nothing (fun v -> Just (f v))*)


(* ----------------------- *)
(* bind                    *)
(* ----------------------- *)

(*val bind : forall 'a 'b. maybe 'a -> ('a -> maybe 'b) -> maybe 'b*) 
(*let bind mb f = maybe Nothing f mb*)
