対策

2016-09-11 4 views
4

の単位でレコードに拡張メソッドを追加すると、なぜこの作業を行います。対策

type Money = 
    { Amount : decimal } with 

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

が、これは代わりに、私は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

+2

残念ながら、それはです。問題は '0M <_>'は一般的な値とは見なされず、 '0.0 <_>'は一般的な値と見なされます。 – kvb

+0

@kvbこれは「なぜ?質問の一部、ある意味で。それを答えに変換してください。そうすれば、妥当な投票権を得ることができます。 – GregC

答えて

4

DecimalWithMeasureが有用である得ることはありませ

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

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

んここに。たとえば、これは私のために動作します:あなたが代わりに `` float`のdecimal`を使用しているので、

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

    member m.gotMoney() : bool = 
     let zero = LanguagePrimitives.DecimalWithMeasure<'currency> 0M 
     m.Amount > zero 
関連する問題