您如何解释像 Ring 和 Yesod 这样的纯功能 Web 服务器不是 MVC?

How do you explain that purely functional web servers like Ring and Yesod are not MVCs?

传统上人们将 Web 应用程序视为 MVC - 它假定一个面向对象的上下文。

函数式编程对此进行了批判 - 并提供了一个使用高阶函数和不可变数据结构的模型。

我的问题是:您如何解释像 Ring 和 Yesod 这样的纯功能 Web 服务器不是 MVC?

高阶函数和不可变数据结构是函数式编程的意义所在,就像 classes/objects 是 OOP 的意义一样,因此功能性 Web 服务器框架主要使用功能性工具(函数)似乎很自然, 数据结构)尽可能。

http://www.yesodweb.com/book/routing-and-handlers 以 "If we look at Yesod as a Model-View-Controller framework," 开头......所以我似乎不太明白你的问题。你是什​​么意思?

我将尝试就 Yesod 回答这个问题。

How do you explain that purely functional web servers like Ring and Yesod are not MVCs?

Yesod 不是网络服务器。 Yesod 是一个网络框架。 warp 是与 Yesod 一起使用的推荐网络服务器。

How do you explain that purely functional web servers like Ring and Yesod are not MVCs?

这不一定是真的。您可以使用 templates as view, persistent as model and routing and handing as Controller. In fact, the scaffolding site 松散地遵循 MVC 方法。

Functional programming critiques this - and offers a model using higher order functions and immutable data structures.

这与此 MVC 无关。 MVC只是一种设计模式。高阶函数和不可变数据结构不会阻止您遵循某些体系结构或设计模式。

您可以为 MVC 假设 OO 上下文,这就是它诞生的地方,但您当然不必这样做。 MVC 只是说 Model、View 和 Controller 应该是独立的事物,它们以特定的方式进行交互;在 OO 语言中,将它们表示为 类 很方便,但这不是必需的。参见例如MVC and Purity:

Having been exposed to purely functional programming, I now believe that the controller and model/view separation is precisely the separation between side-effectful code (IO) and pure code.

Ring 足够低级,因此谈论它是否是 MVC 是没有意义的:它只是您对 HTTP 协议的适配器。您可以读取请求 headers/body,写入响应 headers/body,等等,但是环本身没有关于更新域对象的内容;这取决于你在戒指上的任何层数。