Say we got a very simple function
let fn a = a.ToString()
This type is inferred as a -> string
However, passing a unit value to a function throws a NullReferenceException.
In the case of simple functions like the ones described above, this can easily work, but I am in a more complex scenario:
let eitherToHttp e =
match e with
| Either.Ok v -> OK (v.ToString())
| Either.Bad reason -> reasonToErrorCode reason
Type this Either<'a, RejectReason> -> WebPart(that WebPartand Eitheractually it does not matter here)
In a scenario where the type eis equal Either<unit, RejectReason>, the function is thrown just like in a simple scenario.
How can I handle this? Should types be inferred as generic if this does not actually work for ALL types?