Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Haskell todo-example

Haskell todo-example

Lightning Talk at New York Haskell User Group on a simple todo list server with a REST API, written in Haskell using our own frameworks Welshy and TX, with a simple UI displaying the interaction with the API

Haskell todo-example on GitHub: https://github.com/mcschroeder/todo-example

Jürgen Cito

October 04, 2013
Tweet

More Decks by Jürgen Cito

Other Decks in Programming

Transcript

  1. todo-example Showcase of a lightweight web application written in Haskell

    J¨ urgen Cito Vienna Univeristy of Technology, Austria New York Haskell User Group October 2nd, 2013 1 / 6
  2. Intro – todo-example • What is it? “A simple todo

    list server with a REST API, written in Haskell using Welshy and TX, with a simple UI displaying the interaction with the API” • Resulted from a project in ’Industrial Haskell’ at Vienna UT in a group with Michael Schr¨ oder and Harald Steinlechner (held by hvr1 - lecture notes avaible2) 1https://github.com/hvr 2http://hvr.github.io/VU183653/2013S/ 2 / 6
  3. Welshy • REST DSL based on Scotty3 • Goal: Easier

    error handling and convenience functions • halt the current action at any point unless (length > 0) (halt $ status badRequest400) • built-in error handling for queryParam, jsonParam, bearerAuth • Action monad is an Alternative instance offset <- queryParam "offset" <|> return 0 3http://hackage.haskell.org/package/scotty 3 / 6
  4. TX • Persistent transactions on top of STM • Similar

    to acid-state • Very simple (∼100 lines of code) class SafeCopy (Update d) => Persistable d where data Update d replay :: Update d -> TX d () ... data MyDB = MyDB { posts :: TVar [String] } instance Persistable MyDB where data Update MyDB = CreatePost String | ModifyPost Int String replay (CreatePost p) = void $ createPost p replay (ModifyPost n p) = modifyPost n p 4 / 6
  5. Future Work • Get rid of JS4 – GHCJS? •

    Long polling list <- getList listId check $ now < listUpdatedAt list return list • Improve Welshy, TX 4http://www.haskell.org/haskellwiki/The_JavaScript_Problem 5 / 6
  6. Where? Where to find this – Hackage/Github: • todo-example: https://github.com/mcschroeder/todo-example

    • Welshy: http://hackage.haskell.org/package/welshy • TX: http://hackage.haskell.org/package/tx Who to contact: • Michael Schr¨ oder (twitter: @schrototo) • Harald Steinlechner (github: haraldsteinlechner) • J¨ urgen Cito (twitter: @citostyle) 6 / 6