In the following code, note the type constraint for get_Zero:
type Wrapper<'t> = { Data : 't[] }
let compute<'t
when 't : (static member get_Zero : unit -> 't)
and 't : (static member (~-) : 't -> 't)
and 't : (static member (+) : 't * 't -> 't)>
(wrapper : Wrapper<'t>) =
wrapper.Data
|> Seq.mapi (fun i value -> (i, value))
|> Seq.sumBy (fun (i, value) ->
if i % 2 = 0 then value
else -value)
Even though I already have an explicit type constraint, I'm still getting the following compiler error on the call to Seq.sumBy:
A type parameter is missing a constraint 'when ^t : (static member get_Zero : -> ^t)'
Anyone know what's going on here? Thanks.
static memberetc constraints, then the function must beinlineand instead of using'T, use^tinstead (meaning:^, not'). See also: docs.microsoft.com/en-us/dotnet/fsharp/language-reference/… - Abel