2011-04-03 85 views
0

我从书中尝试此代码但遇到错误,有人可以帮我吗?查找字符串中的单词的简单代码

#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编译器说:

多种类型存在所谓的 '设置',以通用参数的不同的号码。提供一个类型实例化来消除类型分辨率,例如'设置< _>'。

这是什么意思?

+5

标题是一个*小*误导.. – Mehrdad 2011-04-03 05:37:13

回答

0

我想你应该尝试像

Set<string>.Create() 

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

3

问题是有两种类型命名为Set:F#的一个和PowerPack中的一个(实际上有三种类型,但没关系)。在你的情况下,F#Set类型会做得很好,所以你不需要PowerPack中的标签Set。请尝试以下代码:

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)