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