11 2012 档案

摘要:或许你对这个词有点陌生,但是如果说到F#中的Sequence表达式,Async结构时,你或许会有点印象。其实这两种表达式均可以理解为Computation Expression.如果你对Sequence表达式这个名词感觉很陌生的话,那先弄些代码来看看:let seqExpr = seq{ for i in [1..10] do yield i }相信看到上面的代码你应该知道神马叫Sequence表达式了。。。下面是Async的代码片断:let asyncExpr path = async{ let fileStr ... 阅读全文
posted @ 2012-11-22 21:55 ZackZhou 阅读(1281) 评论(4) 推荐(1) 编辑
摘要:F# 的快排实现起来很简单,因为集合类List里面的方法帮用户实现了大部分的代码。下面就是就是代码:let rec quickSort (list : int list) = match list with | [] -> [] | [single] -> [single] | head :: tail -> let leftList = tail |> List.choose(fun item -> if item <= head then Some(item) else No... 阅读全文
posted @ 2012-11-21 15:25 ZackZhou 阅读(377) 评论(0) 推荐(0) 编辑
摘要:本文转自: Prbert Pickering的博客。原文链接:http://strangelights.com/blog/archive/2011/09/18/first-example-of-a-very-simple-type-provider.aspx原文内容:I have an idea for a type provider, so now that the type provider bits are finally publicly available I set to work building it. However it turns out just implementin 阅读全文
posted @ 2012-11-20 15:17 ZackZhou 阅读(311) 评论(0) 推荐(0) 编辑
摘要:使用F# 的时候老是会忘记List 里面的函数的使用方法,可能是有些的确是用的有点少,今天把这些都试了一下,弄了点注释,把结果运行结果也弄上去了,方便以后查看:)。说明一下:如果函数使用的List为SrcA 和SrcB,说明此函数需要的两个链表必须为等长的。如果使用的是Src 和Src2 则没有这样的限制。 下面就贴出代码:):let src = [1;4;2;3]let src2 = [3;7;5;3;5]let srcA = [1;2;3;4]let srcB = [4;3;2;1]let myAdd x y = x + ylet operator x y z= x + y... 阅读全文
posted @ 2012-11-19 17:58 ZackZhou 阅读(1514) 评论(0) 推荐(2) 编辑
摘要:关于F#3.0的新功能Type provider,微软为我们提供了内置的6种type providers,用来处理不同数据存储结构.但是有些情况这些内置的方法并不能满足需求,因此就需要用户自己定义适合自己需求的TP。那么在自定义TP前,应该要考虑是不是真的需要自定义TP: 是否有一不受程序逻辑影响,不经常变动的schema(比如数据库由表、记录、字段、索引等组成) 是否经常需要使用到此TP 当程序运行时,此schema是否经常变动Ok,在定义自己的TP前,需要去F# sample pack中下载两个源文件:SampleProviders ->Shared,然后在你的F#库文件中将其加入, 阅读全文
posted @ 2012-11-17 18:55 ZackZhou 阅读(1665) 评论(0) 推荐(1) 编辑
摘要:由于每次到项目统计的时候,都需要统计一下Run的分析情况,手动来做会非常麻烦,由此想写一个小程序统计一下分析情况,下面是代码:// Learn more about F# at http://fsharp.net// See the 'F# Tutorial' project for more help.#r @"C:\Program Files()\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v4.0\Type Providers\FSharp.Data.TypeProviders.dll"#r @& 阅读全文
posted @ 2012-11-12 12:33 ZackZhou 阅读(344) 评论(0) 推荐(0) 编辑
摘要:这个是很早很早之前作的一个小东西,不过由于工作时间原因,没能做好,留个笔记:// Learn more about F# at http://fsharp.net//namespace WeatherDemo#if INTERACTIVE#r @"C:\Program Files\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v4.0\Type Providers\FSharp.Data.TypeProviders.dll"#r @"C:\Program Files\Reference Assemblies\M 阅读全文
posted @ 2012-11-12 12:27 ZackZhou 阅读(420) 评论(0) 推荐(0) 编辑
摘要:当时根据涛哥的要求,做了一个小工具,具体作用就是上传或下载指定类型文件到云服务器。当时涛哥正在做VS的一个插件: F# snippet,类似于C#中的.net AutoCode v4.0,区别就在于它们工作的语言不同。这个工具使用到了F#3.0的新功能:Type Provider and Query.如果你想尝试一下这个工具(当然,你需要做些修改:)),那么你需要F# 3.0 或者 VS2012。如果只想了解一下这个工具,也不错~ 呵呵下面是代码:)// Learn more about F# at http://fsharp.net// See the 'F# Tutorial 阅读全文
posted @ 2012-11-12 10:53 ZackZhou 阅读(2174) 评论(1) 推荐(0) 编辑
摘要:对于F#程序员来说,修改特定内存地址空间的值并不是一件很常见的事,和C#一样,F#代码由F#编译器编译之后生产托管模块,但是F#中并没有提供C#中的unsafe功能,那么如何在F#中修改给定内存地址空间的值呢,下面的这些代码就可实现此要求://Memory Address,you may get this address from some other operations//not sure if this is readable safe addresslet p = 0x002100000n//Pointer to the Addresslet address : nativeptr&l 阅读全文
posted @ 2012-11-10 15:04 ZackZhou 阅读(281) 评论(0) 推荐(0) 编辑
摘要:在做这个面试题之前,我们需要了解一下关于Ascii码的一些知识: 0~31及127(共33个)是控制字符或通信专用字符(其余为可显示字符) 32~126(共95个)是字符(32sp是空格),其中48~57为0到9十个阿拉伯数字 65~90为26个大写英文字母,97~122号为26个小写英文字母,其余为一些标点符号、运算符号等 后128个称为扩展ASCII码,目前许多基于x86的系统都支持使用扩展(或“高”)ASCII。扩展ASCII 码允许将每个字符的第8 位 用于确定附加的128 个特殊符号字符、外来语字母和图形符号Ok,知道这些后,先把代码贴出来:module CountNumb... 阅读全文
posted @ 2012-11-10 12:38 ZackZhou 阅读(1242) 评论(1) 推荐(0) 编辑
摘要:看书笔记~,如有错误,说明看书不认真~~ 这个不好画画。。 就弄成个图片了。 阅读全文
posted @ 2012-11-09 16:46 ZackZhou 阅读(272) 评论(0) 推荐(0) 编辑
摘要:之前在TryFsharp上发不过一系列F#的东西,现在挪到这来了:),列一下:入门1:http://www.cnblogs.com/tryfsharp/archive/2011/12/31/2308503.html入门2:http://www.cnblogs.com/tryfsharp/archive/2011/12/31/2308504.html入门3:http://www.cnblogs.com/tryfsharp/archive/2012/01/04/2312153.html入门4:http://www.cnblogs.com/tryfsharp/archive/2012/01/04/2 阅读全文
posted @ 2012-11-08 20:23 ZackZhou 阅读(311) 评论(0) 推荐(1) 编辑
摘要:继上一篇的深度遍历,下面实现以下图的广度遍历,广度遍历中使用到了队列, 即代码中的let nodesQueue = new Queue<Node>(),由于F# 中没有指针,如果我们需要在递归中保存一个随时会发生变化的值时,我会选择ref类型的变量。 下面顺便说说ref类型变量的一些基本操作:let x = ref 1 定义一个ref类型的变量let getValue = !x !x用来获取此ref变量的值,这里将其值赋给了getValue变量x:=2 将x 的值变为2let newValue = !x 这里,变量newValue的值就是2了。接下来就是此遍历的具体代码了,没有什. 阅读全文
posted @ 2012-11-08 18:15 ZackZhou 阅读(1218) 评论(0) 推荐(1) 编辑
摘要:下面是图中的深度遍历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 阅读(258) 评论(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 阅读(1340) 评论(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 阅读(664) 评论(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 阅读(375) 评论(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 阅读(215) 评论(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 阅读(184) 评论(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 阅读(159) 评论(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 阅读(181) 评论(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 阅读(190) 评论(1) 推荐(0) 编辑

点击右上角即可分享
微信分享提示