simple code to find a word in a string
i try this code from book but get an error, can somebody help me?
#if INTERACTIVE
#r "FSharp.PowerPack.dll";;
#r "FSharp.PowerPack.Compatibility.dll";;
#endif
open System
ope开发者_开发知识库n 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)
For Set.Create
the compiler says:
Multiple types exist called 'Set', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. 'Set<_>'.
What does it mean?
The problem is that there are two types named Set
: F#'s one and the one in the PowerPack (actually there are three types, but that doesn't matter). In your case the F# Set
type will do just fine so you don't need the tagged Set
from the PowerPack. Try the following code:
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)
I think you should try something like
Set<string>.Create()
to define the datatypes that will be stored in the set.
精彩评论