在同一个解决方案中混合F#和C#的模式 [英] Patterns to mix F# and C# in the same solution

查看:60
本文介绍了在同一个解决方案中混合F#和C#的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了很少的功能语言,主要用于学术目的。然而,当我必须投入一个客户端 - 服务器应用程序时,我总是开始采用域驱动设计,严格的oop。



在.Net框架中编写的一个复杂的解决方案可以得到利用超过一种语言的优势,有时甚至超过一种范式。混合C或C ++与LUA或Python是一个常见的做法,有时嵌入序言可能非常有趣。
我从来没有尝试混合OOP和功能范例。



F#是一种较新的功能和面向对象语言,我看到这在技术上很容易将C# F#库在同一个解决方案中。但是我想知道是否有任何意义:我使用Linq来满足我的许多功能需求。



你什么时候和如何,你认为混合这两个语言在一起?
我想知道是否存在一组尝试这样的模式。



您是否在C#解决方案中使用F#?

解决方案

传统功能技术有一定的意义,导致代码更小更简洁。一个典型的例子是文本解析和树处理,当您实现DSL时,它们通常出现在一起。 F#功能像匿名迭代器,可扩展模式匹配以及定义自定义中缀运算符作为组合器的能力真的有很大的帮助。同时,在C#方面,LINQ是一个很好的开始,但它并不会让你一路走来。



我建议你看一下 FParsec ,并且看到自己比您可能写的任何图书馆更适合高级文本处理/解析在C#中。


I studied few functional languages, mostly for academical purposes. Nevertheless, when I have to project a client-server application I always start adopting a Domain Driven Design, strictly oop.

A complex solution written in a .Net framework could get advantages using more than a language and sometimes more than a paradigm. Mixing C or C++ with LUA or Python is a common practice, sometimes embedding prolog can be very interesting. I never tried to mix OOP and functional paradigm.

F# is a newer functional and object oriented language, I see that's it's technically very easy to mix C# with F# libraries in the same solution. But I wonder if it makes any sense: I use Linq to satisfy many of my functional requirements.

When and how, do you think it's a good idea to mix these two languages together? I wonder if exists a set of patterns that tries that.

Do you actually use F# in a C# solution?

解决方案

There are certain places where traditional functional techniques make a lot of sense, and lead to code that is both smaller and more concise. A classic example is text parsing and tree processing, both often appearing together when you're implementing a DSL. F# features like anonymous iterators, extensible pattern matching, and ability to define custom infix operators to serve as combinators really helps a lot here. Meanwhile, on the C# side, LINQ is a good start, but it doesn't take you all the way there.

I suggest you have a look at FParsec, and see for yourself how much better suited it is to advanced text processing / parsing than any library you could possibly write in C#.

这篇关于在同一个解决方案中混合F#和C#的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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