]> Git — Sourcephile - haskell/literate-web.git/blob - tests/Examples/Ex02.hs
impl: use newer symantic-base
[haskell/literate-web.git] / tests / Examples / Ex02.hs
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE PartialTypeSignatures #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# OPTIONS_GHC -Wno-missing-signatures #-}
5
6 module Examples.Ex02 where
7
8 import Literate.Web hiding (index)
9 import Relude
10
11 -- | A convenient data-type to avoid using Eithers-of-Tuples or Tuples-of-Functions.
12 data Route
13 = Index
14 | About
15 deriving (Eq, Show, Generic)
16
17 -- | Using Generic, 'dataType' derives
18 -- from the 'Route' algebraic data-type
19 -- a function transforming Eithers-of-Tuples into a 'Route'.
20 router =
21 dataType @Route
22 $ pathSegment "index" -- <.> response @Char @'[PlainText]
23 <+> "about"
24 </> pathSegment "me"
25
26 -- <. response2 @Char @'[PlainText]
27
28 content = \case
29 -- In -> Out
30 Index{} -> return "INDEX"
31 About -> return "ABOUT"
32
33 -- c0 = compile CompilerEnv{} router content
34
35 address_IndexMe :: Address
36 address_IndexMe = address router Index
37
38 address_AboutMe :: Address
39 address_AboutMe = address router About