I've been flailing for many many hours on pattern matching & discriminated unions. I'm trying something very simple. What I *want* to write is:
type Hours =
| Hour24 of int
| Hour12 of int
let (|Hour24|Hour12|) time =
match time with //incomplete pattern match
| Hour12 time when time>0 && time<=12 -> Hour12 time
| Hour24 time when time>12 && time<=24 -> Hour24 time
let matcht t =
match t with
| Hour12 t -> t
| Hour24 t -> t
but this gives an incomplete match error for time. So I try the following :
type Hours =
| Hour24 of int
| Hour12 of int
| Badhour
let (|Hour24|Hour12|) time =
match time with
| Hour12 time when time>0 && time<=12 -> Hour12 time
| Hour24 time when time>12 && time<=24 -> Hour24 time
| Badhour -> Badhour
let matcht t =
match t with
| Hour12 t -> t
| Hour24 t -> t
| Badhour -> (*what goes here?*)
I get why that pattern matching is incomplete but I don't know how to handle matching an error & what would be idiomatic F#.