]> Git — Sourcephile - webc.git/blob - tests/Examples/Ex01.hs
impl: generate routes from a model
[webc.git] / tests / Examples / Ex01.hs
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# OPTIONS_GHC -Wno-missing-signatures #-}
4
5 module Examples.Ex01 where
6
7 import Relude
8 import Symantic.Classes (SumFunctor (..), adt)
9
10 import Webc
11
12 -- | A convenient data-type to avoid using 'Either's and Tuples.
13 data Site
14 = Index
15 | About
16 -- Contact URI.Slug
17 -- Post [URI.Slug]
18 deriving (Eq, Show, Generic)
19
20 -- | Polymorphic expression describing the website,
21 -- to be instantiated to the various interpreters.
22 -- NoMonomorphismRestriction is used to avoid specifying manually
23 -- the inferred symantic classes.
24 site =
25 -- site :: IsoFunctor repr => SumFunctor repr => Slugable repr => repr Site
26 -- Using Generic, 'adt' derives (Iso{a2b, b2a} <%>)
27 -- from the 'Site' algebraic data-type.
28 adt @Site $
29 literalSlug "index.html"
30 <+> literalSlug "about.html"
31
32 -- <+> captureSlug "user" <. literalSlug "contact.html"
33 -- <+> "post" </> many0 (captureSlug "dir")