Reputation: 1858
I've tried something like this:
type DateResult = | ValidDate of DateTime | NullableDate | BlahBlah
let validateDate entry =
match entry with
| :? DateTime as x -> ValidDate x // error here
| :? Nullable<DateTime> as x -> NullableDate
| _ BlahBlah
But this does not work. Is this possible? What is the recommended way of handling a problem like this?
Upvotes: 0
Views: 130
Reputation: 4280
DateTime
and Nullable<DateTime>
are different types and compiler cannot infer what is the type of parameter entry
. Use type annotation:
let validateDate (entry: obj) =
match entry with
| :? DateTime as x -> ValidDate x
| :? Nullable<DateTime> as x -> NullableDate
| _ BlahBlah
Upvotes: 4