4

Why does this work:

type Money = 
   { Amount : decimal } with

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

but this doesn't

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

GregC
  • 7,737
  • 2
  • 53
  • 67
  • 2
    Unfortunately, it's because you're using `decimal` instead of `float`. The issue is that `0M<_>` is not considered a generic value, while `0.0<_>` is. – kvb Sep 11 '16 at 21:38
  • @kvb This answers the "why?" part of the question, in a way. Please convert it to an answer so you could get a well-deserved up-vote. – GregC Sep 11 '16 at 23:46

1 Answers1

5

DecimalWithMeasure is useful 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
Grundoon
  • 2,734
  • 1
  • 18
  • 21