我是F#的新手,想得到一个建议.
我想使用GetDigitValue函数.
open System
open System.Drawing
open System.Globalization
let getSubscript ichar =
match ichar with
|1 -> GetDigitValue(843)
| _ -> GetDigitVale(852)
Run Code Online (Sandbox Code Playgroud)
我有以下错误:未定义值或构造函数'getDigitValue".
0.1 + 0.2 == 0.3 ==> False
Run Code Online (Sandbox Code Playgroud)
我在python,c#,c ++,F#,Visual Basic.NET,ASP.NET中尝试过这个!
0.1 + 0.2 == 0.30000000000000004 ==> True
Run Code Online (Sandbox Code Playgroud)
对于我上面提到的所有语言,这都是正确的.为什么会出现这种不合逻辑的不平等?
如何在 F# 中覆盖 MouseMove(或任何与此相关的鼠标事件),类似于在 C# 中的实现方式?意思是我想写这样的东西,只是为了获取当前的鼠标坐标。
override form.MouseMove e =
mouseX = e.X
mouseY = e.Y
Run Code Online (Sandbox Code Playgroud)
编辑:基本上我想访问 MouseEventArgs,在这段代码中,参数 e 被解释为 PaintEventArgs。
第二次编辑:这段代码实际上有效,只是有另一个代码块覆盖了 OnPaint 事件,所以显然我不能对 F# 中的两个覆盖使用相同的事件参数变量 (e)。
我有个问题:
我在F#中使用Async.Sleep()方法时遇到问题.这是我程序中的一段代码:
if (newAngle <> currentAngle) then
if (newAngle = 0) then
Motor(MotorPort.OutA).SetSpeed(100y)
angle1 <- Motor(MotorPort.OutA).GetTachoCount()
**Async.Sleep(20)**
angle2 <- Motor(MotorPort.OutA).GetTachoCount()
speed <- abs(angle2 - angle1)
distance <- abs(newAngle - angle2)
if (speed > 11) then
pwr <- 20L + int64 distance
if (pwr < 100L) then
Motor(MotorPort.OutA).SetSpeed(sbyte pwr)
while (distance > 30 || angle2 <> angle1) do
angle1 <- Motor(MotorPort.OutA).GetTachoCount()
**Async.Sleep(20)**
angle2 <- Motor(MotorPort.OutA).GetTachoCount()
speed <- abs(angle2 - angle1)
distance <- abs(newAngle - angle2)
if (speed > 11) then
pwr …Run Code Online (Sandbox Code Playgroud) 我在C#中有一个扩展方法:
Foo(this Bar bar, int x)
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
我如何在F#中调用它?
bar.Foo(100); // Doesn't work
bar.Namespace.Foo(100); // Doesn't work
Run Code Online (Sandbox Code Playgroud)
如何在F#中的.NET列表中使用扩展方法Sum的答案?需要打开模块.我可以不使用扩展方法open吗?
我只是想知道是否有更好的写作方式:
|> Seq.isEmpty |> not
Run Code Online (Sandbox Code Playgroud)
就像是:
|> not Seq.isEmpty
Run Code Online (Sandbox Code Playgroud) 什么原因导致REPL打印函数签名而不是函数结果?
我试图执行以下行:
let email = Email "abc.com";;
email |> sendMessage |> ignore;;
Run Code Online (Sandbox Code Playgroud)
代码如下
type PhoneNumber =
{ CountryCode:int
Number:string }
type ContactMethod =
| Email of string
| PhoneNumber of PhoneNumber
let sendMessage contact = function
| Email _ -> printf "Sending message via email"
| PhoneNumber phone -> printf "Sending message via phone"
// c. Create two values, one for the email address case and
// one for the phone number case, and pass them to sendMessage.
let email …Run Code Online (Sandbox Code Playgroud) 我的数据是SEQUENCE:
[(40,"TX");(48,"MO");(15,"TX");(78,"TN");(41,"VT")]
我的代码如下:
type Csvfile = CsvProvider<somefile>
let data = Csvfile.GetSample().Rows
let nullid row =
row.Id = 15
let otherid row =
row.Id= 40
let iddata =
data
|> Seq.filter (not nullid)
|> Seq.filter (not otherid)
Run Code Online (Sandbox Code Playgroud)
我创建了这些功能.
然后我想调用那些函数的"not"来将它们从序列中过滤掉.
但问题是我在前两个函数中遇到"row.Id"错误,因为你只能用一个类型来做.
我如何解决这个问题,以便我能成功地解决这个问题.
我的结果应该是SEQUENCE:
[(48,"MO);(78,"TN");(41,"VT")]
我已尽一切努力使编译器能够监听。但是,它拒绝理解。我正在尝试比较每个元素的颜色值,如果它们相同,则返回true,否则返回false。
我放置了想要的约束,但仍然无法确定类型。
let all_same_color cs =
let mutable d=true
let (col:Color) = card_color (cs.Head:Card)
for i in cs do
let col=card_color i
if not (col = col) then
printfn "Black"
d<-false
else
d<-d
printfn "Val %b" d
d
Run Code Online (Sandbox Code Playgroud)
我希望如果颜色匹配则返回true,否则返回false。
它在这一行不断出错:
let (col:Color) = card_color (cs.Head:Card)
Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this programpoint to constrain the type of the object. This may allow the …Run Code Online (Sandbox Code Playgroud) 我是 F# 的新手,我正在努力弄清楚如何将浮点数列表中的数字组合成浮点数。
如果我有名单
let floatList = [ 9.0; 8.0; 3.0 ]
我想要一个返回值是浮点数 983.0 的函数。我将如何解决这个问题?