F#:是否没有UI(如WPF)? [英] F#: is there no UI (like WPF) for it?

查看:73
本文介绍了F#:是否没有UI(如WPF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近看了一些关于F#的视频.看来它主要用于服务或类?我在VS2010 Beta中没有看到"F#WPF"应用程序?

i recently saw some videos on F#. it seems it used mainly for Service or Classes only? i see no "F# WPF" app in VS2010 Beta?

推荐答案

F#实际上具有一些非常好的结构来创建事件驱动的UI应用程序,例如

F# actually has some very nice constructs for creating event-driven UI applications, such as First Class Events, Object Expressions, calling property setters from a constructor e.g.:

new Form(Text="My Window Title", Width=600, Height=400)

还有很多

但是,在VS中创建 forms designer 会为您的语言重新定义CodeDom.只要您的语言看上去完全像C#或VB一样,当前的CodeDom体系结构就可以很好地工作;它不适合生成F#代码(这是我现在无法找到的网络广播或采访中的代码).它还需要局部类,如果我没记错的话,从Beta 1开始就不支持该部分类.F#团队决定将他们的资源用于增强该语言的其他部分,而不是专注于第一版中的设计器支持,例如异步和并行编程等.

However, creating a forms designer in VS reqiures a CodeDom for your language. The current CodeDom architecture works great, as long as your language looks exactly like C# or VB; it does not lend itself well to generation of F# code (this from a webcast or interview that I can't locate right now). It also requires partial classes, which if I recall correctly, are not supported in the language as of Beta 1. Rather than focus on designer support in the first release, the F# team decided to spend their resources on enhancing other parts of the language, such as asynchronous and parallel programming, etc.

这意味着您至少有4种选择来在F#中创建UI:

What this means is that you have at least 4 choices for creating UI in F#:

  • Write all UI code by hand, which is fine for simple apps;
  • Create your F# code as a library to handle the "hard parts," like asynchronous and parallel code, or computation centric code, and call it from C#/VB;
  • Create your UI code as a C#/VB library, and both drive it from F# and delegate event handling to F#; or
  • Use a DSL or Computation Expression (monad) to simplify building the UI by hand (just discovered this while looking for other links in this answer).

在这些方法中,从F#调用C#UI库可能是最灵活的,同时仍然保留了熟悉的范例.但是,使用计算表达式快速手动构建UI确实值得一看.

Of these, calling a C# UI library from F# may be the most flexible while still retaining a familiar paradigm. But, using computation expressions for quickly building UI by hand is certainly worth looking at.

这篇关于F#:是否没有UI(如WPF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆