4 ms·
In Standard ML, it would be a type error to do that specifically: - if true then "abc" else 2.01; stdIn:1.2-1.30 Error: types of if branches do not agr
by saityi 6y ago
In Standard ML, it would be a type error to do that specifically:
- if true then "abc" else 2.01;
stdIn:1.2-1.30 Error: types of if branches do not agree [tycon mismatch]
then branch: string
else branch: real
in expression:
if true then "abc" else 2.01
You would need to define a new data type to wrap them:
- datatype string_or_real = r of real | s of string;
- if true then s "abc" else r 2.01;
val it = s "abc" : string_or_real