]> Git — Sourcephile - haskell/literate-web.git/blob - tests/Examples/Ex02.hs
init
[haskell/literate-web.git] / tests / Examples / Ex02.hs
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# OPTIONS_GHC -Wno-missing-signatures #-}
4
5 module Examples.Ex02 where
6
7 import Literate.Web hiding (index)
8 import Relude
9
10 -- | A convenient data-type to avoid using Eithers-of-Tuples or Tuples-of-Functions.
11 data Route
12 = Index
13 | About
14 deriving (Eq, Show, Generic)
15
16 -- | Using Generic, 'dataType' derives
17 -- from the 'Route' algebraic data-type
18 -- a function transforming Eithers-of-Tuples into a 'Route'.
19 router =
20 dataType @Route $
21 pathSegment "index"
22 <+> "about"
23 </> pathSegment "me"
24
25 content = \case
26 Index -> return "INDEX"
27 About -> return "ABOUT"