C# 这个Scala代码在惯用C语言中看起来如何?
在为我们正在进行的.Net项目研究XMPP时,我遇到了这段非常好看的Scala代码:C# 这个Scala代码在惯用C语言中看起来如何?,c#,scala,concurrency,xmpp,actor,C#,Scala,Concurrency,Xmpp,Actor,在为我们正在进行的.Net项目研究XMPP时,我遇到了这段非常好看的Scala代码: object Main { /** * @param args the command line arguments */ def main(args: Array[String]) :Unit = { new XMPPComponent( new ComponentConfig() { def secret() : String = {
object Main {
/**
* @param args the command line arguments
*/
def main(args: Array[String]) :Unit = {
new XMPPComponent(
new ComponentConfig() {
def secret() : String = { "secret.goes.here" }
def server() : String = { "communitivity.com" }
def subdomain() : String = { "weather" }
def name() : String = { "US Weather" }
def description() : String = { "Weather component that also supported SPARQL/XMPP" }
},
actor {
loop {
react {
case (pkt:Packet, out : Actor) =>
Console.println("Received packet...\n"+pkt.toXML)
pkt match {
case message:Message =>
val reply = new Message()
reply.setTo(message.getFrom())
reply.setFrom(message.getTo())
reply.setType(message.getType())
reply.setThread(message.getThread())
reply.setBody("Received '"+message.getBody()+"', tyvm")
out ! reply
case _ =>
Console.println("Received something other than Message")
}
case _ =>
Console.println("Received something other than (Packet, actor)")
}
}
}
).start
}
}
(这是取自)
参与者和模式匹配看起来是一种以可伸缩方式编写组件的非常好的方法。我还没有找到任何看起来成熟的C#actors库,而学习Axum似乎有些过头了
在C#中,什么是解决这个问题的正确方法?(当然,忽略特定于XMPP的代码-我更感兴趣的是C版本的Actor和模式匹配是什么样子的)。有一些Actor-like库可用于.NET,也有类似的库
也看到这个 我真的不确定什么才算是答案。C#有一些扩展可以促进函数式编程风格,但它仍然是一种命令式语言。我认为这个示例中的功能并不难复制,但它要么是命令式风格,要么是模仿函数式语言特性的笨拙。我想在不改变编程语言的情况下,retlang可能是最可行的解决方案,谢谢