在Visual Studio 2008中编译F#程序.

在Visual Studio 2008中,编译F#程序时,会出现警告(但不是错误),但是由于这个警告却使你的程序无法运行,不过大多数据这些警告都会有提示,提示你用.NET里的函数代替F#中的某些函数,但是这些.NET中的函数又不能像在C#中那样使用.

例如:

#light

let one = ["one "]
let two = "two " :: one
let three = "three " :: two
let rightWayRound = List.rev three
let printList l =
List.iter print_string l
print_newline()
let main() =
printList one
printList two
printList three
printList rightWayRound
main()

上面的程序在Visual Studio 2008编译时,会出现警告,提示List.iter print_string l一行中print_string要用Console.Write()代替,但是如果直接把print_string直接用Console.Write()或Console.Write也还是不行.

那么到底如果使用Console.Write()代替print_string在Viusal Studio 2008中通过编译呢,

注意Console.Wirite有多个重载版本,重载时要指明版本,这要用到匿名函数并对参数进行注解

所以上面的List.iter print_string l

可改写为List.iter (fun (x:string) -> Console.Write(x)) l

这样就可以通过编译了.

原文地址:https://www.cnblogs.com/mcjtcnblog/p/1385735.html