维坦
感谢您的关注!
-
Oct29No Comments
Silverlight Tools
Silverlight Toolkit
http://www.codeplex.com/Silverlight
Silverlight Toolkit 是什么?
Silverlight Toolkit 是搜集 Silverlight 控件, 组件和在 Silverlight 发行版之外有用的部分. 它为设计和开发人员迅速的提供新功能, 还能借力社区以便帮助快速定位 创意和 BUG 修复. 第一个发行版本包含 12 个新控件 (图表 样式 布局和用户输入) 的完整源代码 单元测试, 例子和文档.
演示地址:
http://silverlight.net/samples/sl2/toolkitcontrolsamples/run/default.html
http://silverlight.net/samples/sl2/toolkitchartsamples/run/default.html
-
Oct18No Comments
背景: 在我还对程序开发比较迷糊的时候, 曾经听说过一个问题, 编写一段程序, 运行的结果是输出程序的全部源代码(一字不差).
当初曾经有很多人认为这是不可能的, 因为这与逻辑相悖, 不过后来真的有人用纯C做到了, 思路一出, 其他版本纷纷涌现.
这是一个老问题了, 今天在订阅里意外的看到一篇文章:
代码摘自自: Brian Inside F#
#light open System let nl = new String([|char 13;char 10|]) let quote = char 34 let Quote (s:String) = s.Replace(new String([|quote|]), new String([|char 92; quote|])) let Quine s = String.Format("let s = {0}{1}{2}{3}printf {4}%s%s{5} s (Quine s){6}", [| box quote; box (Quote s); box quote; box nl; box quote; box quote; box nl|]) let s = "#light open System let nl = new String([|char 13;char 10|]) let quote = char 34 let Quote (s:String) = s.Replace(new String([|quote|]), new String([|char 92; quote|])) let Quine s = String.Format(\"let s = {0}{1}{2}{3}printf {4}%s%s{5} s (Quine s){6}\", [| box quote; box (Quote s); box quote; box nl; box quote; box quote; box nl|]) " printf "%s%s" s (Quine s)
-
Oct18No Comments
安装体验较之前的版本好了很多 可以自动对之前的版本进行卸载, 不过强烈建议还是先卸载旧版本之后再装.
另外:
从 Shawn Burke's Blog 看到了 Silverlight 接下来的走向, 我们可以看到实际上控件还是很丰富的, 为了尽可能的减少运行时的体积, 非内置的控件将会以控件包的形式发布:
_2.jpg)
-
Sep261 Comment
Visual Studio 2008 Tools RC0:
http://go.microsoft.com/fwlink/?LinkId=129043Expression Blend SP1 RC0:
http://www.microsoft.com/expression/try-it/default.aspx?filter=prereleaseWindows Silverlight 2 Dev Runtime RC0:
http://go.microsoft.com/fwlink/?linkid=129011我是从 http://silverlight.net/forums/p/30209/97238.aspx#97238 得知的消息之后转到 http://silverlight.net/blogs/msnow/archive/2008/09/25/silverlight-version-2-rc0-released.aspx 找到的下载地址, 详细的我也没来得及细看, 就是这样...
突然发现近来莫名其妙的忙...
补充: 中文版VS2008用户稍安勿燥
Installation Requirements:
Visual Studio 2008 (English) or Visual Web Developer Express 2008 (English) must be installed before installation of Silverlight Tools can continue. Silverlight Tools is available in other languages at http://go.microsoft.com/fwlink/?LinkId=120319.
Build 9.0.30729.XX of Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 must be installed before installation can continue. See http://go.microsoft.com/fwlink/?LinkID=122094 for download information.
Beta and preview versions of Microsoft Expression Blend must be uninstalled before installation can continue.
-
Sep81 Comment
我在初学 F# 的时候, 对 C# 只能算是一知半解, 甚至可以说是个门外汉, 所以我一直没有机会去深刻的领会什么是 OOP, 连最基本的类都定义不好. 反倒是学习 F# 后, 经常需要到网络上搜索一些 C# 代码再转换, 这样才能 C# 有了一些了解...
我说我连类都定义不好, 这是个很尴尬的事实. 比如像 C# 的可视化设计器生成的代码那样, 新建一个 Form 修改窗口标题, 再加入一个Button. 这是再简单不过的例子了, 可是用 F# 该如何写呢?
// 例子程序里展示了如何使用 FP 的风格建立窗体 let form = let form = new Form(Text = "MyForm") let b = new Button() form.Controls.Add b form // 但是今天我们要讨论的是如何像 C# 那样继承自 Form 实现自己的类 // 第一种方法是我在 Simple101 中看到的 // 这是一种被称为详尽语法(Explicit syntax) // 这是最中规中矩的定义方式 当然也最繁琐 type MyForm1 = inherit Form val b :Button member t.InitializeComponent() = t.Text <- "MyForm1" t.Controls.Add t.b new() as t = { b = new Button() } then t.InitializeComponent() // 第二种是很常规的定义类的方法 // 被称为隐含语法(Implicit syntax) // 隐含了什么? 我猜是隐含了构造函数吧 // 之前一直疑惑构造函数隐含了 那我怎么调用呢? type MyForm2() = inherit Form() let b = new Button() member t.InitializeComponent() = t.Text <- "MyForm2" t.Controls.Add b // 感谢 Tomas Petricek // 我一直不解的问题终于解开了 原来可以后接 as 语法来指向自己 type MyForm3() as t = inherit Form() let b = new Button() do t.Text <- "MyForm3" t.Controls.Add b // 感谢 Danny Asher // 他的方法提醒了我基类的方法是可以直接调用的 type MyForm4() = inherit Form() let b = new Button() do base.Text <- "MyForm4" base.Controls.Add b
-
Sep6No Comments
更新如下:
- 修正包含单位的浮点型类型缩写行为
- 修正Quotations.Expr.TupleGet 零索引异常
- CodeDom 使用 '--nologo' 参数
- 修正 decimal
不支持操作符的问题 修正包括 'let' 和 'use' 的序列化表达式回收 enumerator 过早的问题 修正对有效的表达式评估不成功的问题 (Credit Suisse 报告) 修正对象表达式中的 base 变量与类型中的 base 变量行为不一致的问题
-
Aug301 Comment
原文链接:
先说说我自己的试用体验:
- 源代码可以排序了, 右键菜单上虽然没有显示快捷键, 但是可以通过按 ALT + Up/Down 来换位.
- CTRL + E, C 注释的时候不再是 (* *) 了, 而是与 C# 相同的多行 //.
- CTRL + K, F 代码格式化仍然不可用, 哭...
- 智能感知比之前流畅了些, 但仍有待提高, 回车换行后仍然不能自动缩进.
工具:
项目文件
- 项目文件扩展名改为 .fsproj 并且支持 MSBuild.
引用文件
- #r 引用现在只能用于 .fsx 文件
- 在 Windows 平台上使用 #r 引用注册表 AssemblyFoldersEx 中的程序集时不必指定路径. (指在添加引用对话框中默认可见的程序集, 例如可以直接 #r "System.Xml.Linq.dll")
- 默认情况下脚本是不包含在项目中的(不参与编译), 而且你必须另外详尽的指定所引用的程序集(项目引用不等于脚本能用).
- #load 对智能感知也会有作用.
- #use 被移除了.
编译器命令行
- --generate-interface-file 改为 --sig
- --no-warn 改为 --nowarn
- -O3 改为 -optimize 或 -O
语言:
度量单位的推导与检查
- [<Measure>]
type 米
[<Measure>]
type 秒let dist = 100.0<米>
let time = 9.69<秒>
let speed = dist / time // val it : float<米/秒> = 10.31991744
// let foo = dist + time // 错误: The unit of measure '秒' does not match the unit of measure '米'
轻量级语法
- #light 和 #light "off" 在 .fs .fsx .fsi 文件中是必须的, 但在 .ml 和 .mli 文件中隐含为 #light "off".
隐式转换
- 可能之前你已经听说过 F# 放弃隐式转换的一个理由是类型推断, 但是适当的时候如果能实现自动 Upcast 也不错:
// Class
type Base() =
member b.X = 1
type Derived(i : int) =
inherit Base() // 顺便说句: 继承之后的 as base 已经不可用了, 默认即为 base
member d.Y = i
let d = new Derived(7)
let f (b : Base) = b.X
let res = f d// Record
type Rec = { A : Base ; X : int }
let r = { A = new Derived(7); X = 12}// Union
type Uni = A of Base | X of int
let u = A(new Derived(7))// Mutable field
type Rec2 = { mutable A : Base ; X : int }
let r2 = { A = new Derived(7); X = 12}
r2.A <- new Derived(3) - 以下情况不适用:
// tuple creation
// list elements
// function binding and "return types"
// if/then/else
改进工程实践
- #nowarn 的范围扩大到文件末尾 (为什么不是项目末尾?)
- open 打开命名空间必须指定完整路径
open System
open Windows // 警告
open Forms // 警告
open System.Windows.Forms // 正确
命名空间缩写
- 模块缩写不能用于命名空间
module WF = System.Windows.Forms // 错误 因为 Forms 不是模块.
assert(false)
- assert 现在与 System.Diagnostics.Debug.Assert 相同, 在 Release 版本中忽略.
AutoOpenAttribute
- // 当命名空间被打开时, 模块也随之自动打开.
namespace ViTarn
[<AutoOpen>]
module Utils
支持 COM 自动和可选参数
操作符的定义更加简单
- type Receiver(latestMessage:string) =
static member (<--) (receiver:Receiver,message:string) =
Receiver(message)
static member (-->) (message,receiver:Receiver) =
Receiver(message)
let r = Receiver "no message"
r <-- "Message One"
"Message Two" --> r
分割操作
- 自定义分割操作符变的更加简单
e1.[e2opt.. e3opt] --> e1.GetSlice(arg2,arg3)
e1.[*] --> e1.GetSlice(None,None)
序列和计算表达式
- 省略执行命令时的 do 前缀
let s =
seq { for i in 1..12 do
printfn "i = %A" i
yield i+2 } - let 拥有与常规相同的语法
let s2 =
async { let rec f x = f x + 1
return 1 } - 序列化表达式要有 seq 前缀
seq {1; 2; 3} - -> 和 ->> 在除 seq 之外的地方声明反对
内置函数也会产生代码
改进调试
- 增强了单步调试, 虽然这已经是 .NET 上其他编译器都具备的, 但在 F# 编译器上必须禁用 tailcalls (--optimize- notailcalls)
库:
反射
- Microsoft.FSharp.Reflection 更趋向于 .NET 内置的反射.
引用
- 可用的命名空间:
Microsoft.FSharp.Quotations
Microsoft.FSharp.Quotations.Patterns
Microsoft.FSharp.Quotations.DerivedPatterns
Microsoft.FSharp.Quotations.ExprShape - Microsoft.FSharp.Quotations.Raw 和 Microsoft.FSharp.Quotations.Typed 被移除
- Expr<_> 变成 Expr 的子类型.
- 值的结合 "comes for free"
let f (x:int) = <@ 3 + x @> - 表达式的结合使用 %expr
let f (expr:Expr) = <@ 3 + %expr @> - 原本的活动匹配在这里 Microsoft.FSharp.Quotations.Patterns, 还有些帮助类在 Microsoft.FSharp.Quotations.DerivedPatterns.
- BindingPattern 更名为 ExprShape
事件和委托
- IEvent 模块更名为 Event, Event.create 语法不变.
- 创建正规的事件 new Event<args>() 或者指定委托类型 new Event<delegate,args>().
- 触发事件 ev.Trigger(args) 或 ev.Trigger(sender,args)
- 公开事件 ev.Publish
- 类型 IHandlerEvent<_> 被删除.
- 例如:
type MyControl() =
let tickEvent = new Event<int>()
member self.React() =
tickEvent.Trigger (4)
member self.OnTick = tickEvent.Publish
已删除的特性
- Unicode 语法
- IEnumerable.*
- List.of_IEnumerable List.to_IEnumerable (取而者: List.of_seq List.to_seq)
- Permutation 类型
- Func.*
- CompatArray 和 CompatMatrix 模块. (取而者: Array Array2)
- Microsoft.FSharp.Compatibility.CompatMatrix (仅 .NET1.1)
- Microsoft.FSharp.Compatibility.CompatMatrix (仅 .NET1.1)
- Microsoft.FSharp.Compatibility.CompatArray (仅 .NET1.1)
- Microsoft.FSharp.Core.Idioms
- Microsoft.FSharp.Core.Int8
- Microsoft.FSharp.Core.Int16
- string 现在是函数 'a -> string. 因此 string.Format 不可用, 使用 System.String.Format 代替. 同样 string.Empty 也不可用.
- base 变成关键字
- truncate 的类型改为 'a -> 'a (支持所有带 Truncate 静态方法的浮点型)
- (type ty) 改为 typeof<ty> 和 typedefof<ty>
- 抽象类必须标记 [<AbstractClass>]
- 声明即可以解释为函数也可以解释为样式.
let Node(x,l1,r1) = idxToNode(m1) // 不总是函数定义
F# PowerPack
- 用于收集 F# 的扩展和兼容功能, 未来计划在 codeplex 上开源.
- 兼容于 Ocaml 或早期版本的组件
- Math 组件, 包括 Matrix 和 Vector 类型
- 度量单位定义组件
- 一些不赞成使用的组件
- LINQ
- 如果你不想让程序依赖附属的库, 就必须修改不赞成使用的部分, 例如:
Sys.argv --> System.Environment.GetCommandLineArgs()
Char.code --> int
Char.chr --> char
Filename.* --> Use System.IO.Path methods instead
Bytearray --> Array
FSharp.PowerPack.Linq.dll
- PowerPack 支持通过 LINQ 表达式引用编辑和赋值
open Microsoft.FSharp.Linq.QuotationEvaluation
let q = <@ 1 + 1 @>
q.ToLinqExpression () // 转换为 LINQ 表达式
q.Compile () // 返回类型 'unit -> int'
q.Eval () // 返回 2 - PowerPack 支持通过 LINQ 表达式查询赋值
open Microsoft.FSharp.Linq.Query
type Customer = { Name:string; Data: int; Cost:float; Sizes: int list }
let c1 = { Name="Don"; Data=6; Cost=6.2; Sizes=[1;2;3;4] }
let c2 = { Name="Peter"; Data=7; Cost=4.2; Sizes=[10;20;30;40] }
let c3 = { Name="Freddy"; Data=8; Cost=9.2; Sizes=[11;12;13;14] }
let c4 = { Name="Freddi"; Data=8; Cost=1.0; Sizes=[21;22;23;24] }
let data = [c1;c2;c3;c4]
let db = System.Linq.Queryable.AsQueryable<Customer>(data |> List.to_seq)
// 执行查询
<@ seq { for i in db do
for j in db do
yield (i.Name,j.Name) } @>

评论