Open
Description
Repro steps
let inline test<'T when 'T :> INumber<'T>> x:'T =
if x > 'T.Zero then x
else 'T.Zero
Actual behavior
Compilation error:
Severity Code Description Project File Line Suppression State
Error FS0193 A type parameter is missing a constraint 'when 'T: comparison' FSharpTests Program.fs 37 Active
Expected behavior
Compiles like C# counterpart:
public T Tets<T>(T x) where T : INumber<T> => x > T.Zero ? x : T.Zero;
Known workarounds
Add the constraint:
let inline test<'T when 'T :> INumber<'T> and 'T:comparison> x:'T =
if x > 'T.Zero then x
else 'T.Zero
Related information
- Operating system Win 11
- .NET 7
- Visual Studio 17.4
Metadata
Metadata
Assignees
Type
Projects
Status
New