generics - F# Static Member Type Constraints -


I'm trying to define a function, segment, which uses a lack of structural type ( Static members require zero, one, +, and /) similar to Seq.sum so that it can be used with int, long, bilint etc. I do not think the syntax is right, and many resources can not be found on this topic. Please help me

  inline forkike (n: ^ NUM) = ^ NUM: (static member get_Zero: unit-> (^ NUM)) ^ NUM: (stable member get_One: unit> (^ NUM )) Let's break the rec (n: ^ NUM) (j: ^ NUM) (flist: ^ NUM list) = if n = ^ NUM.One then flist elif n% j = ^ NUM.Zero then block (N / J) (^ NUM.One + ^ NUM.One) (J :: flist) and blocking n (J + ^ NUM.One) (flist) segmenting n (^ NUM.One + ^ NUM.One) []   

Here's how I write it:

  Module NumericLiteralG = Go Inline FromZero Start () = LanguagePrimitives.GenericZero Inline FromOne () = LanguagePrimitives.GenericOne If you want to break the Nline, go to N = J to REC NJ flist = Finish if n = 1G then flist elif n% j = 0G then blocking (N / J) J (J :: flist) and segment n (J + 1G) The type of inferred type is very common al here, but as you expect, the function will function if you want to normalize (flvd) type (n 1G + 1G) []  

By expressing some common expressions explicitly, you need to have more sensible signatures and difficulties Force the set:

  Inline factorial (n: ^ a): ^ a list = let (a: ^ a) = 1g go (zero: ^ a) = 0g REC segmentation n (j: ^ a) flist = if n = flist elif n% j = zeros (n / j) j (j :: flist) and forkier n (j + one) (flist) Factorial N (one + one) []  

Comments