6

Just looking at Haskell and web frameworks and wondering if it would make sense to use Haskell's great threading/event functionality to power a platform for writing HTML5 and REST apps that expose an HTTP API for data and a WebSocket (with maybe SockJS support for appropriate fallback) API for events? It doesn't seem like the "big" web frameworks support WebSockets as a first-class citizen, though they seem to have a lot of other things going for them.

My concern is making use of available cores, which Haskell can do well, but also providing easy user integration on the server side for validation and server-side logic (maybe by embedding Lua or similar?). If one wrote this on the JVM, one could make use of multiple server-side language support and lots of libraries for this sort of thing.

I'm sure people are doing things like this in a one-off solution for their own applications but I'm thinking along the lines of a PaaS-type approach where one can write HTML5 apps with data (including proper synchronization for offline use) and eventing "for free" as a fundamental part of the platform. Most logic would reside in the browser but some could be run on the server with the appropriate hooks and a reasonable embeddability (JavaScript seems out of the question and not sure about embedding interpreters in Haskell as I'm only dangerously familiar with Haskell in general).

Part of the problem I've had with Haskell so far is that I'm not a Math guy. I didn't study CS in college and I'm a creative-type thinker. So a lot of the tutorials and documentation get me pretty lost, especially when dealing with the mathematical stuff.

Has anyone trod this path already? Am I late to the party? :)

Jon Brisbin
  • 1,299
  • 8
  • 11
  • 1
    Have you looked at Yesod and Snap? They both support WebSockets... and it looks like someone is working on SockJS support too: https://github.com/bitonic/sockjs-haskell – Nathan Howell Jun 06 '12 at 00:00

2 Answers2

4

Gregory Collins gave a tutorial at CUFP last year about using Snap to build an interactive chat website using long polling (not websockets). The source code is here.

In the websockets department, Jasper Van der Jeugt wrote a Haskell websockets library. It is available on hackage and comes with websockets-snap, which provides Snap framework support. There's also wai-websockets which provides integration with Warp.

mightybyte
  • 7,282
  • 3
  • 23
  • 39
  • I noticed that hackage library but wasn't sure about its production quality and how it actually integrated with Snap. I was really hoping to find something that was a true first-class citizen of a web framework and not an addition that maybe works but doesn't provide good integration. That said, I'll certainly take a closer look at Snap and websockets (again). – Jon Brisbin Jun 07 '12 at 01:54
  • I discussed [here](http://stackoverflow.com/questions/5645168/comparing-haskells-snap-and-yesod-web-frameworks/5650715#5650715) and [here](http://softwaresimply.blogspot.com/2012/04/hopefully-fair-and-useful-comparison-of.html) how Haskell web frameworks are very modular and interchangeable, and I would argue that this trend extends to the websockets library and beyond. I think it is Haskell's extremely high abstraction capabilities that facilitate this to a greater degree than the vast majority of other languages. You probably won't need things to be baked in as much as you're used to. – mightybyte Jun 07 '12 at 03:56
2

I believe all of the major frameworks have some level of websockets support, so they should all be a fair choice based on your requirements. For Yesod, there's an example of creating a chat system (using eventsource, not websockets) available in the book:

http://www.yesodweb.com/book/wiki-chat-example

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
  • I actually like Yesod quite a bit so far. It seems quite fast if one is to believe the benchmarks. :) While the eventsource stuff might work okay, I'm really looking for websocket or preferably SockJS (which includes fallback) support. – Jon Brisbin Jun 07 '12 at 01:56
  • have you written a warp tutorial somewhere? I haven't been able to find much in the way of straightforward documentation on how to use warp to write a REST app. A kind of "warp for dummies" type of thing... – Jon Brisbin Jun 07 '12 at 02:01
  • The closest is the README.md for WAI: https://github.com/yesodweb/wai/blob/master/wai/README.md . There aren't that many people writing web apps directly against WAI (though some do exist). – Michael Snoyman Jun 07 '12 at 03:13