Is F# a usable language for .net windows development

僤鯓⒐⒋嵵緔 提交于 2020-01-01 08:40:43

问题


I have been hearing about F# and Microsoft now have a guy who is blogging and coding away in redmond somewhere about it. Can you really write GUI code from F# (I'd love to see an example of say adding a button to a form and subscribing to the onclick event for instance)

Does F# have full access to all of .Net?

I'm honestly curious and I know I could google but I'd love to hear from someone who is really using the language.


回答1:


Yes, you can certainly write WinForms apps - although you wouldn't override the OnClick method, you'd subscribe to the Click event.

Yes, F# has full access to .NET, although you won't get very idiomatic functional code if you use a lot of mutable types.

Tomáš Petříček's F# web site has sample source code from his book (disclaimer: I'm involved with the book too, so I'm clearly biased) which has WinForms examples.




回答2:


I'd highly recommend this excellent post by Scott Hanselman, which points to some F# resources including examples and presentations.




回答3:


But as Jon Skeet says, Tomas has some interesting examples (especially filtering/piping events), which show what I suspect may be a good cross-over point, i.e., design your C# GUI with designer, and then write the brains in F#, hooking one to the other with events.

That's I think a very good approach. Designing complex GUIs without WinForms designer is a bit annoying (though, the difference isn't that big in WPF - F# doesn't support WPF designer, but you don't loose that many things there).

Anyway, stay tuned for more examples :-). Using declarative event handling (Event.filter, Event.map & friends) is quite nice, but in some cases it isn't quite what you want to. I'm just writing a chapter about that and I think F# gives you some really awesome ways to deal with GUIs - the source code will be freely available on the book web site and I'll hopefuly write some short intro for my blog as well once the book will be done.




回答4:


I haven't actually used F#, only read the specs. It may be great for WinForms development, but my immediate reaction to this is "it doesn't really matter". As long as you use CLR compliant compilers you should be able to mix F# assemblies with others written in C#/IronPython/etc.

Yes, F# can use the .NET Framework, and F# assemblies can be used by other .NET assemblies.

My advice would be to code your functional libraries in F# and then use whichever .NET language you fancy to write the client app(s).




回答5:


You CAN write GUI code from F#, but I'm not sure that you'd WANT to. If you are the kind who wrote your C# GUIs in notepad anyway, then it probably wouldn't bother you. Personally I prefer the designer, and there isn't one for F#, and as far as I've understood it, there isn't going to be one either - which probably says something about the intended use of F#.

But as Jon Skeet says, Tomas has some interesting examples (especially filtering/piping events), which show what I suspect may be a good cross-over point, i.e., design your C# GUI with designer, and then write the brains in F#, hooking one to the other with events.



来源:https://stackoverflow.com/questions/556510/is-f-a-usable-language-for-net-windows-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!