2016-06-17 3 views
1

私は私がエラー error FS1129: The type 'Option' does not contain a field 'XsdLocation'f#で型定義されたオブジェクトから新しい不変オブジェクトを生成する方法は?

+0

私はこれを行う方法だと思っていました。オンラインの多くの例は、これを他のレコードタイプと一緒に示しています。また、私はf#にはとても新しいので、これを調べるキーワードがわからない。 – XenoPuTtSs

答えて

4

あなたが定義されたオブジェクトは、標準の.NET class、ないrecordあり得る

type Option(xsdLocation:string, xmlDirectory:string) = 
    member this.XsdLocation = xsdLocation 
    member this.XmlDirectory = xmlDirectory 

let a1 = new Option("xsd","xml") 
let a2 = {a1 with XsdLocation = "xsd2"} 

が動作していない、このコードを持っています。

type Option = {XsdLocation : string; XmlDirectory : string} 

let a1 = {XsdLocation = "xsd"; XmlDirectory = "xml"} 
let a2 = {a1 with XsdLocation = "xsd2"} 

PS:あなたはそのように定義する必要がありwith構文を使用したい場合はOptionはビルトインタイプですので、私はまた、あなたのタイプのためにOption以外の名前を選ぶお勧めします。

+0

ありがとうございます。私はあなたの助言に基づいて使用していた名前を変更しました。 – XenoPuTtSs

関連する問題