Copy the first demo program from Expert F# to VS2008. There has a compiler error with split function when I compiler the program. I found a solution from internet likes below:
Listing 2-1. Analyzing a String for Duplicate Words
#light
/// Analyze a string for duplicate words
let wordCount text =
let words = String.split [' '] text
let wordSet = Set.of_list words
let nWords = words.Length
let nDups = words.Length - wordSet.Count
(nWords,nDups)
let showWordCount text =
let nWords,nDups = wordCount text
printfn "--> %d words in the text" nWords
printfn "--> %d duplicate words" nDups
开始错误:error FS0039: The value, constructor, namespace or type 'split' is not defined. A construct with this name was found in FSharp.PowerPack.dll, which contains some modules and types that were implicitly referenced in some previous versions of F#. You may need to add an explicit reference to this DLL in order to compile this code.
解决:在代码前面添加 #r @"FSharp.PowerPack";;(不过这只在F# Interactive (Console)下管用)。在.net里在工程文件的引用里添加FSharp.PowerPack.dll
-----创建一个工程项目的时候,带了一个引用文件夹,这里面可以添加你项目要用的库------
右键单击“References”选择“Add References”,进去后选择“.NET”下的“FSharp.PowerPack”,然后确定就OK了。
Thanks the guy shared this on his blog.
Another way to run the demo program is on command line.
1. Open a command line window
2. Go to the FSharp installed path
3. Type the fsi.exe (it is the F# interactive environment)
4. Type #help;; command, it will show the help of F# interactive environment.
5. Copy the demo program and paste it to command line window, notice: should type the ;; at the end.
If you press the enter key, you will get a compiler error about the split function. Now, we know the DLL file missed. We can use the
#r "FSharp.PowerPack.dll";;
command to set reference dll file.
6. Paste the program again, then you will get the
val wordCount : string -> int * int
val showWordCount : string -> unit
If you get the message, it means your first F# program works well now.