Adding an extension method to a unit record

Why does it work:

type Money = 
   { Amount : decimal } with

   member inline m.gotMoney : bool =
      m.Amount > 0M

But it is not

type MoneyUOM<[<Measure>]'currency> = 
   { Amount : decimal<'currency> } with

   member inline m.gotMoney : bool =
      m.Amount > 0M<_>

Instead i get error FS0339: The signature and implementation are not compatible because the type parameter in the class/signature has a different compile-time requirement to the one in the member/implementation

+4
source share
1 answer

DecimalWithMeasureuseful here. For example, this works for me:

type MoneyUOM<[<Measure>]'currency> = 
   { Amount : decimal<'currency> } with

   member m.gotMoney() : bool =
      let zero = LanguagePrimitives.DecimalWithMeasure<'currency> 0M
      m.Amount > zero
+4
source

Source: https://habr.com/ru/post/1654284/


All Articles