public
Created

Yesod routing with QuasiQuotes

  • Download Gist
hello-no-qq.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses,
TemplateHaskell, OverloadedStrings #-}
import Yesod
import Yesod.Routes.TH
 
data HelloWorld = HelloWorld
 
mkYesod "HelloWorld"
[ ResourceLeaf Resource
{ resourceName = "HomeR"
, resourcePieces = []
, resourceDispatch = Methods Nothing ["GET"]
}
, ResourceLeaf Resource
{ resourceName = "FibR"
, resourcePieces =
[ (True, Static "fib")
, (True, Dynamic "Int")
]
, resourceDispatch = Methods Nothing ["GET"]
}
]
 
instance Yesod HelloWorld
 
getHomeR :: Handler RepHtml
getHomeR = defaultLayout $ toWidget $ const ("Hello World" :: Html)
 
fibs :: [Int]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
 
getFibR :: Int -> Handler RepHtml
getFibR i = defaultLayout $ toWidget $ const $ toHtml $ fibs !! i
 
main :: IO ()
main = warpDebug 3000 HelloWorld

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.