标签: f#

F#GetDigitValue值或构造无效

我是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".

f#

-1
推荐指数
1
解决办法
132
查看次数

Python,C++,C#,F#中不合逻辑的不等式

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)

对于我上面提到的所有语言,这都是正确的.为什么会出现这种不合逻辑的不平等?

c# c++ python math f#

-1
推荐指数
1
解决办法
314
查看次数

在 F# 中覆盖 MouseMove 事件

如何在 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# c#-to-f#

-1
推荐指数
1
解决办法
210
查看次数

在F#中精确使用Async.Sleep()

我有个问题:

我在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)

f# asynchronous

-1
推荐指数
2
解决办法
1402
查看次数

如何在不打开的情况下从F#调用C#扩展方法?

我在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吗?

c# clr extension-methods f#

-1
推荐指数
1
解决办法
95
查看次数

更好的方式''|> Seq.isEmpty |> not'

我只是想知道是否有更好的写作方式:

|> Seq.isEmpty |> not
Run Code Online (Sandbox Code Playgroud)

就像是:

|> not Seq.isEmpty
Run Code Online (Sandbox Code Playgroud)

f#

-1
推荐指数
1
解决办法
294
查看次数

什么原因导致REPL打印函数签名而不是函数结果?

什么原因导致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)

f#

-1
推荐指数
1
解决办法
91
查看次数

尝试创建一个函数,然后在F#中通过"not that function"过滤序列

我的数据是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")]

f#

-1
推荐指数
1
解决办法
108
查看次数

F#拒绝基于多个约束确定类型

我已尽一切努力使编译器能够监听。但是,它拒绝理解。我正在尝试比较每个元素的颜色值,如果它们相同,则返回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# types list

-1
推荐指数
1
解决办法
57
查看次数

F# 将浮点列表合并为浮点数

我是 F# 的新手,我正在努力弄清楚如何将浮点数列表中的数字组合成浮点数。

如果我有名单

let floatList = [ 9.0; 8.0; 3.0 ]

我想要一个返回值是浮点数 983.0 的函数。我将如何解决这个问题?

f#

-1
推荐指数
1
解决办法
108
查看次数

标签 统计

f# ×10

c# ×2

asynchronous ×1

c#-to-f# ×1

c++ ×1

clr ×1

extension-methods ×1

list ×1

math ×1

python ×1

types ×1