我使用VisualStudio2008IntegratedShell和F# CTP (10月)。一切都很好,但是当我试图打开System.Windows.Forms,VS时会出现一个错误:the namespace 'Windows' is not defined。
但是,当我试图在F#交互式中打开名称空间时,它可以工作。
我做错了什么?
如何使用F#度量单位来模拟某些几何形状的面积。
到目前为止,我所掌握的代码是这样的,但是它还没有完全编译。
[<Measure>] type radius
[<Measure>] type PI
[<Measure>] type area
let convertRadiusToArea (r:float<radius>) : float<area> =
// let pi = System.Math.PI
let a:float<PI> = 3.14<PI>
r * r * Syst
我真的可以在F#中做一些尾部调用优化的工作。我正试图解析一棵类似于树的结构,并对每一片叶子进行计算。
我遇到问题的函数是calcLength
type Location = float * float
type Radius = float
type Width = float
type Angle = float
type Primitive =
| Circle of Location * Radius
| Ellipse of Location * Radius * Radius
| Square of Location *
我试图效仿这个例子(来自p137 of Rob的 ),但我无法让它与最新的F# CTP协同工作。
我似乎忽略了第3行中“值”的定义。
Value.GetInfo(x)
这就产生了:
error FS0039:未定义命名空间或模块“值”。
有人能告诉我这是从哪里来的吗?如果现在做的不一样,那么新语法是什么?(温柔点--这是我第一次和F#玩)
下面是我工作的例子:-
#light
open Microsoft.FSharp.Reflection
let printTupleValues x =
match Value.GetInfo(x) with
| TupleValue
我需要帮助逆转F#中的位数,就像在这个问题中所做的那样。我是F#的新手,我想知道我们怎么能做到这一点?
let bitreverse x =
let mutable b = 0
while x do
b >>>= 1
b|= x & 1
x >>>= 1
b
我甚至不确定这里的语法是否正确。我对这门语言很熟悉。
为了计算正方形和圆的面积,我定义了以下类型:
type Square = {width: float; length: float;} with
member this.area = this.width * this.length
member this.perimeter = (this.width + this.length) * 2.
type Circle = {r:float} with
member this.area = System.Math.PI * this.r * this.r
member this.perimeter = 2. *