1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE UndecidableInstances #-}
5 {-# LANGUAGE NoMonomorphismRestriction #-}
6 {-# OPTIONS_GHC -Wno-missing-signatures #-}
8 module Examples.Ex02 where
11 import Data.Function (($), (.))
12 import Data.Maybe (Maybe (..))
14 import Data.Set qualified as Set
15 import GHC.Generics (Generic)
16 import Network.URI.Slug qualified as URI
17 import Symantic.Classes (
26 import Symantic.Reader (Reader (..))
27 import Text.Show (Show)
35 -- SitePage [URI.Slug]
36 -- SiteSpecial [URI.Slug]
37 deriving (Eq, Show, Generic)
40 gen0 = generate (unReader site model0)
44 encode (unReader site model0) $
47 { filterLang = Just LangFr
54 <+> literalSlug "feed"
55 <+> "filter" </> infer
58 -- ("page" </> many1 (captureSlug "page"))
60 -- ("special" </> many1 (captureSlug "page"))
64 { filterLang :: Maybe Lang
65 , filterTag :: Maybe Tag
67 deriving (Eq, Show, Generic)
80 infer = adt @Filter $ adt (literalSlug "all" <+> infer) <.> optional infer
83 data Lang = LangEn | LangFr deriving (Eq, Show, Generic)
84 instance (IsoFunctor repr, SumFunctor repr, Slugable repr) => Inferable Lang repr where
85 infer = adt @Lang $ literalSlug "fr" <+> literalSlug "en"
89 { modelTags :: Set URI.Slug
93 model0 = Model{modelTags = Set.fromList ["tag0", "tag1"]}
96 newtype Tag = Tag {unTag :: URI.Slug} deriving (Eq, Show)
98 instance (IsoFunctor repr, Slugable repr) => Inferable Tag (Reader Model repr) where
99 infer = Reader $ (Iso Tag unTag <%>) . chooseSlug . modelTags