小编Ole*_*nov的帖子

如何在F#中创建COM对象

我需要IMessage接口.在C#我可以写

CDO.Message oMsg = new CDO.Message(); // ok
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在F#中这样做时

let oMsg = new CDO.Message()
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息:

'new'不能用于接口类型.考虑使用对象表达式'{new ... with ...}'.

如何解决这个问题呢?

com f#

8
推荐指数
1
解决办法
487
查看次数

具有BOM的UTF-8文件中第一行的长度

下午好.假设我有一个带有单个字母的utf-8文件,比如"f"(没有\n和空格),我试着获得一系列行长度.

(with-open [rdr (reader "test.txt")] 
  (doall (map #(.length %) (line-seq rdr))))
Run Code Online (Sandbox Code Playgroud)

我明白了

=> (2)
Run Code Online (Sandbox Code Playgroud)

为什么?是否有任何优雅的方法来获得第一个字符串的正确长度?

clojure

5
推荐指数
1
解决办法
589
查看次数

当值为"无"时动态确定选项的类型

动态获取Option类型存在一些困难.假设我有一个功能:

let printType x =
   if (box x) = null then printfn "the type is 'null'"
   else printfn "the type is %A" (x.GetType())
Run Code Online (Sandbox Code Playgroud)

我们在这里有输出:

printType 3          // the type is System.Int32
printType (Some(3))  // the type is Microsoft.FSharp.Core.FSharpOption`1[System.Int32]
printType None       // the type is null
printType null       // the type is null
Run Code Online (Sandbox Code Playgroud)

获取表达式的类型时,如何区分None和null?

f# optional

5
推荐指数
2
解决办法
575
查看次数

3
推荐指数
1
解决办法
221
查看次数

标签 统计

f# ×3

clojure ×1

closures ×1

com ×1

mutable ×1

optional ×1

ref ×1