F# Core library source code has a flag for compiling tuples as structs but I can't make it work

妖精的绣舞 提交于 2019-12-10 08:51:55

问题


This is follow-up question to this proposal.

Apparently, the F# Core library source has a flag that allows 2-tuples to be compiled as structs. See here. I did the following:

  • Added a define TUPLE_STRUXT flag to FSharp.Core.fsproj and FSharp.Compiler.fsproj.
  • Built with build.bat.
  • Replaced contents of C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0 and C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.1.0 with appropriate built files.

My project compiles and references the right (newly-built) FSharp.Core.dll. However, 2-tuples are still compiled as classes.

Am I doing something wrong? Or is this code branch in fact irrelevant? The fact that tuples are compiled to System.Tuple and not the type declared in this code (whether the TUPLE_STRUXT flag is set or not) would indicate the latter. Is there a way to make it work?

EDIT: After also setting the flag FX_NO_TUPLE the source does not compile. The error I can't get around is prim-types.fs <527,7>: error FS0039: The type 'Struct' is not defined. That is, the offending line is the first one of the struct tuple definition:

[<Struct>]
type Tuple<'T1,'T2> = 
    new (v1,v2) = { Item1 = v1; Item2 = v2 }
    val Item1 : 'T1 
    val Item2 : 'T2

Does anyone know what causes this?


回答1:


TUPLE_STRUXT depends on another flag, FX_NO_TUPLE, which should also be set.



来源:https://stackoverflow.com/questions/24993904/f-core-library-source-code-has-a-flag-for-compiling-tuples-as-structs-but-i-can

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!