Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 在字符串中查找单词的简单代码_F# - Fatal编程技术网

F# 在字符串中查找单词的简单代码

F# 在字符串中查找单词的简单代码,f#,F#,我尝试了书中的代码,但出现了一个错误,有人能帮我吗 #if INTERACTIVE #r "FSharp.PowerPack.dll";; #r "FSharp.PowerPack.Compatibility.dll";; #endif open System open System.IO open System.Collections.Generic open Microsoft.FSharp.Collections.Tagged let str = "This is a string,

我尝试了书中的代码,但出现了一个错误,有人能帮我吗

#if INTERACTIVE
#r "FSharp.PowerPack.dll";;
#r "FSharp.PowerPack.Compatibility.dll";;
#endif

open System
open System.IO
open System.Collections.Generic
open Microsoft.FSharp.Collections.Tagged

let str = "This is a string, try to break it buddy!\nfind!"

let isWord (words) = 
    let wordTable = Set.Create(words)
    fun w -> wordTable.Contains(w)
对于
Set.Create
,编译器会说:

存在称为“Set”的多个类型,使用不同数量的泛型参数。提供类型实例化以消除类型解析的歧义,例如“Set”


这是什么意思?

我想你应该试试这样的东西

Set<string>.Create()
Set.Create()

定义将存储在集合中的数据类型。

我认为您应该尝试以下方法

Set<string>.Create()
Set.Create()

定义将存储在集合中的数据类型。

问题在于有两种类型名为
set
:F#的一种和PowerPack中的一种(实际上有三种类型,但这并不重要)。在您的情况下,F#
类型可以很好地工作,因此您不需要从PowerPack中获得标记的
。请尝试以下代码:

open System

let str = "This is a string, try to break it buddy!\nfind!"

let isWord words = 
    let wordTable = new Set(words) // or you can use Set.ofArray words
    fun w -> wordTable.Contains(w)

问题是有两种类型,分别命名为
Set
:F#的一种和PowerPack中的一种(实际上有三种类型,但这并不重要)。在您的情况下,F#
类型可以很好地工作,因此您不需要从PowerPack中获得标记的
。请尝试以下代码:

open System

let str = "This is a string, try to break it buddy!\nfind!"

let isWord words = 
    let wordTable = new Set(words) // or you can use Set.ofArray words
    fun w -> wordTable.Contains(w)
这个标题有点误导人这个标题有点误导人。。