Haskell

17 thoughts
last posted Feb. 21, 2014, 6:53 p.m.

7 earlier thoughts

0

I tinkered with Yesod today. I'd love to write out an alternative implementation of the Marconi project (what I'm currently working on) that is based on Haskell rather than Python. Here's what I pulled together today: routes definition in Yesod!

```haskell {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import Data.Text (Text) import Yesod

data App = App

mkYesod "App" [parseRoutes|

-- Fundamental routes: health, homedoc /v1 HomeR GET /v1/health/#Text HealthR GET HEAD

-- Dealing with queues /v1/queues/#Text QueuesR GET /v1/queues/#Text/#Text QueueItemR HEAD GET PUT DELETE /v1/queues/#Text/#Text/stats StatsR GET HEAD /v1/queues/#Text/#Text/metadata MetadataR GET PUT

-- Handling messages /v1/queues/#Text/#Text/messages MessagesR GET POST DELETE /v1/queues/#Text/#Text/messages/#Text MessageItemR GET HEAD DELETE PUT

-- Handling claims /v1/queues/#Text/#Text/claims ClaimsR POST
/v1/queues/#Text/#Text/claims/#Text ClaimItemR GET PATCH DELETE

-- Admin API /v1/shards ShardsR GET
/v1/shards/#Text ShardItemR GET HEAD PUT DELETE PATCH |] ```

It's pretty cool how the routes are typed and how the routes definition is rather self-documenting.

I've also put together a simple implementation of the health resource.

```haskell getHealthR :: Handler () getHealthR Project = return

headHealthR :: Handler () headHealthR Project = getHealthR Project ```

That's all for now. Next up, I'll try and implement another one of the simple resources, perhaps attempting to handle query parameters.

9 later thoughts