module NonNegativeInt =
type T = private | NonNeg of int
type MaybeT =
| Ok of T
| Error of string
let create i =
if (i >= 0 )
then
Ok (NonNeg i)
else Error "i is negative"
let unwrap (t:T ) =
match t with
| NonNeg i -> i
open NonNegativeInt
module Test =
let show (input:MaybeT) =
match input with
| Ok i ->
printfn "%i" ( 10*NonNegativeInt.unwrap (i))
| Error e -> printfn "wronge: %s" e
open Test
show (NonNegativeInt.create -42)
show (NonNegativeInt.create 42)
// union cases not accessible
//show (Ok (NonNeg -1))