12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061openBasetype+'at(* This [Obj.magic] is OK because we never allow user code access to [none] (except via
[unsafe_value]). We disallow [_ Uopt.t Uopt.t], so there is no chance of confusing
[none] with [some none]. And [float Uopt.t array] is similarly disallowed. *)letnone:'at=Stdlib.Obj.magic"Uopt.none"let[@inline]some(x:'a)=letr:'at=Stdlib.Obj.magicxinifphys_equalrnonethenfailwith"Uopt.some Uopt.none";r;;letsome_local=Stdlib.Obj.magicsomeletsome_local:'a.('a[@local])->('at[@local])=some_localletunsafe_value(x:'at):'a=Stdlib.Obj.magicxletunsafe_value_local=Stdlib.Obj.magicunsafe_valueletunsafe_value_local:'a.('at[@local])->('a[@local])=unsafe_value_localletis_nonet=phys_equaltnoneletis_somet=not(is_nonet)letinvariantinvariant_at=ifis_somettheninvariant_a(unsafe_valuet)letsexp_of_tsexp_of_at=ifis_nonetthen[%sexpNone]else[%sexpSome(unsafe_valuet:a)];;letvalue_exnt=ifis_nonetthenfailwith"Uopt.value_exn"elseunsafe_valuetletto_optiont=ifis_nonetthenNoneelseSome(unsafe_valuet)letof_option=function|None->none|Somea->somea;;moduleOptional_syntax=structmoduleOptional_syntax=structletis_none=is_noneletunsafe_value=unsafe_valueendendmoduleLocal=structmoduleOptional_syntax=structmoduleOptional_syntax=structletis_none=is_noneletunsafe_value=unsafe_value_localendendendlet%test_module_=(modulestructlet%expect_test("using the same sentinel value"[@tags"no-js"])=matchsome"Uopt.none"with|(_:stringt)->failwith"should not have gotten to this point"|exception_->();;end);;