摘要: 下面是图中的深度遍历F# 版本,如果有问题还请各位看官不要吝啬指正:)。Graph类在我之前的随笔中已经定义过了,这边直接使用了。type GraphOperations(graph : Graph) = ///depth-first traversal member this.DFSTraverse(action : unit -> unit, startNodeId : string, endNodeId : string) = let visited : string array = Array.zeroCreate graph.Nodes.Length ... 阅读全文
posted @ 2012-11-08 15:18 ZackZhou 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 前段时间从涛哥那学了一招——在递归里面使用Continuation 来避免大量的局部变量的使用,从而避免StackOverflow. 下面是一个小的例子:查找整数数组中的第K大的数:在递归中使用Continuation来避免StackOverflow(查找第K大的数):[<AutoOpen>]module Kmaxtype public Sort() = static member KMax(iArr : int array, kmax : int) = let iLen = iArr.Length match kmax with | sma... 阅读全文
posted @ 2012-11-08 14:45 ZackZhou 阅读(1337) 评论(0) 推荐(1) 编辑
摘要: 这是在工作之余弄了些这个,做的也不太好,留个纪念,今后要用可以做个笔记:)namespace FSharp.Graph#if INTERACTIVE#r "System.Xml.dll"#r "System.Xml.Linq"#endifopen Systemopen System.Xml.Linqopen System.Xmltype Graph() = let mutable nodes = [] let mutable edges = [] member this.Nodes with get() = nodes member this.Edges 阅读全文
posted @ 2012-11-08 10:14 ZackZhou 阅读(658) 评论(0) 推荐(1) 编辑
摘要: 前段时间实现了下这个算法,写的太复杂了,虽然有更简单的F# 版本,不过还是写下来留个纪念:): let rec quickSort (intArray : int array )= match intArray with | empty when empty |> Array.isEmpty -> async {return [||]} | singleValue when (singleValue |> Array.length = 1) -> ... 阅读全文
posted @ 2012-11-07 14:44 ZackZhou 阅读(371) 评论(0) 推荐(0) 编辑
摘要: It's not convenient to get the memory address of object in F#, and the following code will illustrate how to get the memory of given index item of an array://Define your arraylet arr = [|1;23|]//Get the nativeint of arr.[0]let nativeint = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinned 阅读全文
posted @ 2012-11-07 14:36 ZackZhou 阅读(212) 评论(0) 推荐(0) 编辑
摘要: it's quite easy to define a modifiable static property in C# , but in F#,a defined static filed is required first when the class want to define a static property. type StacitMemberCls() = //A static filed should be defined first static let mutable staticFiled = "" static member St... 阅读全文
posted @ 2012-11-07 14:33 ZackZhou 阅读(183) 评论(0) 推荐(0) 编辑
摘要: When we define an F# class in explicit way, it's easy for new F# programmers to make this kind of mistakes when they define mult constructors: people will forget to initliza the class first before use it.type myCls() = //This this a new feature in VS2012,define a property is much easier than bef 阅读全文
posted @ 2012-11-07 14:32 ZackZhou 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Sometimes, we may run into this kind of situation that we want to check if the given method/function has been initialized. We all know this is fairly easy in C#, since we can use delegate to invoke the function , then verify if the value of delegate is null. But in F# , delegate is rarely needed b.. 阅读全文
posted @ 2012-11-07 14:30 ZackZhou 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Because a constant value never changes, constants are always considered to be part of the defining type. In other words, constants are always considered to be static members, not instance members. Defining a constant causes the creation of metadata. When code refers to a constant symbol, compiler... 阅读全文
posted @ 2012-11-07 14:22 ZackZhou 阅读(185) 评论(1) 推荐(0) 编辑