Are there any more original, more functional Haskell web-frameworks? [closed]
Asked Answered
R

4

10

I looked at Haskell web frameworks like Snap and Yesod. Most seem to implement an MVC-ish approach reminding me of web frameworks like Ruby on Rails. Yes, MVC can be achieved with FP, but IMHO it doesn't show the great advantages of an FP approach. As HTTP is a stateless protocol, I would have hoped that there might be an Haskell framework that takes a more original, more pure functional approach. Are there any?

Redbug answered 4/1, 2011 at 20:25 Comment(9)
HTTP may be stateless, but web apps certainly are not.Surakarta
Well, web apps mimic state between requests with things like session state, but there is little intrinsic reason to have state. It's just that developers are so used to look solve it that way (like using server-side sessions)Redbug
@WardB: server-side sessions do offer security / bandwidth savings that would be harder to achieve if every single piece of data was offloaded to the client and had to be transmitted back at each request. Of course, with HTML5 coming up, storing session data on the client side might become easier thanks to the embedded sqlite db; it does not solve the security question, of course. Still an interesting question :)Pennsylvania
@Matthieu That's exactly what I think a proper FP style web framework should never allow. The concept you are talking about sounds like the viewstate used in ASP.Net to simulate a environment with state. Yes, you have input and output in your web app, but you don't require shared state between multiple request lifecycles.Redbug
@WardB: not requiring any state is a pretty bold statement, for example, on amazon, I can select several books before paying. Of course you can forward the list of selected books on each request... but it does not work well when one uses the backbutton :/Pennsylvania
@WardB: I would argue that a webframework that does not allow you to access databases is pretty useless for the vast majority of webapps. But if your output may only depend on the request parameters (and thus not on the contents of the database).Eolande
@sepp2k: Offcourse there needs to be a database, but I think a more functional approach to a web framework has no need for server sessions or building up a response using monads to simulate state.Redbug
@WardB: FWIW, Yesod doesn't use server sessions, rather client sessions. But I think that distinction is meaningless for how "functional" the framework is.Stockade
@WardB: You speak of functional programming as if it's all about avoiding state. It isn't about avoiding state as much as it's about providing a machinery for working with it in a safe way.Metanephros
S
9

I'm not sure which features in FP you would like a framework to utilize, but I think Yesod uses some features to great benefit. (Happstack does as well, but I'm just not as familiar with it.)

  • Type-safe URLs eliminate an entire class of typo-generated bugs, plus automatically deal with input validation.

  • Proper typing practically eliminates XSS attacks.

  • Depending on the scope of data you're dealing with, using either STM or MVars for your storage needs make it easy to avoid race conditions and deadlocks in multi-threaded applications.

I'm sure there's a lot more that I'm not thinking of, but I hope that makes the point. But perhaps what you're looking for is something like a continuation-based framework. I personally think they're a bad idea (I'm a believer in REST), but I suppose it might seem more "functional."

Stockade answered 4/1, 2011 at 21:29 Comment(1)
Thanks for your answer. My understanding of continuations is that it actually is very much about state. The use of the model in web-development tries achieve a simulated statefull environment.Redbug
B
2

It depends what you're trying to achieve. If by stateless you actually mean stateless, I use the templating framework Hakyll to generate static pages. It has an interesting structure to deal with dependencies and file updates.

Bloodhound answered 4/1, 2011 at 20:42 Comment(4)
I didn't mean static pages. Just no shared state between requests/response or side-effectsRedbug
If there's no shared state, and no side effects... What can you do that static pages can't?Contactor
@Carl: the page content might be generated dynamically still (depending on the request parameters).Pennsylvania
I guess he can then implement some simple dispatching depending on the request parameters, serving the correct static page this way.Mistassini
C
2

I think WardB was asking not about fancy types, but rather about the denotative/stateless semantics of FP, in contrast to imperative/nondenotative (and often nondeterministic) semantics of things like IO and STM. It's this denotative aspect that supports precise & tractable reasoning. The term "functional" has been stretched to embrace imperative/nondenotative programming as well, which often leads to confusion. Peter Landin recommended replacing "functional" with "denotative" to help clear up exactly this sort of confusion.

I don't know of any denotative (nonimperative) Haskell web frameworks. Getting there would probably require breaking some long-standing imperative mental habits. Which is to say: interesting work!

Christeenchristel answered 14/4, 2011 at 16:36 Comment(0)
B
1

I was looking for the same but haven't really found it. Specifically I was looking for a continuations approach that renders traditional HTTP sessions unnecessary. These sorts of frameworks are quite popular in Scheme. The closest that I found was Chris Eidhof's answer to the Arc Challenge :-

https://gist.github.com/260052

It's a sketchy prototype and probably many man-months away from being something that you could use for serious work. If my Haskell skills were better, I might be tempted to try and develop it.

I also believe that WASH also took this approach but that seems to have died. I'm pinning my hopes on mysnapsession as I believe that is also looking at a continuations based session facility which would be exciting because I have been very impressed with the quality of the rest of Snap and the momentum behind it.

Big answered 14/4, 2011 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.