I am building a simple interactive program with 2D-graphics, and I'd like to know which combination of Haskell libraries are likely to work. My requirements and ideas-so-far are below:
Fundamental requirements:
- Simple 2-D geometric drawing, of the sort provided by Gloss or Diagrams
- SVG-style interactivity: For example, playing a jigsaw puzzle or Fifteen Game, be able to click on an object and maybe drag it around the canvas.
- (Fallback: Use keyboard navigation to move around the image, activate an object, etc)
Induced Requirements:
- I'd prefer to work in FP Haskell Center, which implies that my UI should be a web app (with Yesod/Snap/Happstack).
If a web app, it could be "image-map" style, where every interaction involves a round-trip to the server, or Javascript style, as with Fay or Elm
Non-requirements:
- This is a self-contained "toy" (like Tangrams or a jigsaw puzzle), so it doesn't need any persistent state in a database
My ideas:
Can anyone suggest set of packages and architecture style that would likely work well together for this UI? My current ideas are:
Yesod with {Gloss or Diagrams} to draw static graphics in FP Haskell Center.
- Then switch to local development to add local native mouse-click interactivity.
- Or use some Ajax solution to send click events back to the server to update graphics
Elm with reactive graphics, without FP Haskell Center
Interactive Javascript experience, written in Fay, compiled to Javascript. (I have never used Fay, I don't know if it can rely on lots of Hackage packages, I know it does not support some extensions, but I don't know if it can use pre-compiled packages that depended on those extensions)
Elm and Fay seem similar, the main differences being that:
- (a) Elm is not actually Haskell
- (b) Fay doesn't enforce FRP style?
Any recommendations?
I'll share my opinion on this matter.
Since Fay compiles to Javascript, and Elm compiles to Javascript, Html and Css I'd say you should give Elm a shot. It's still a bit new but I think it would fit your needs well. You could set up a Snap webserver with websockets (if you wanted to send it to the server that is). This way instead of continuously sending ajax requests you could establish 1 connection.
Of course this depends on how close you want to stay to Haskell. Elm isn't lazy and has no Monadic computations (which means no do syntax). Instead you write it as you would write any pure functions. Signals come close to the IO Monad but are still different.
I don't think you can go wrong with Elm, but I'd recommend looking over your options. Hope your project goes well!