]> Git — Sourcephile - tmp/julm/literate-invoice.git/blob - src/Literate/Database.hs
maint/correctness(Work): use sum type for ScopeId
[tmp/julm/literate-invoice.git] / src / Literate / Database.hs
1 {-# LANGUAGE DeriveAnyClass #-}
2
3 module Literate.Database where
4
5 import Data.List qualified as List
6
7 import Literate.Document qualified as Doc
8 import Literate.Prelude
9
10 class Get to from where
11 get :: from -> to
12
13 newtype Ors a = Ors {unOrs :: Set a}
14 deriving (Eq, Ord, Show, Generic)
15 deriving newtype (NFData)
16
17 instance (Ord a, Doc.ToInline a) => Doc.ToInline (Ors a) where
18 toInline xs =
19 xs
20 & unOrs
21 & toList
22 <&> Doc.toInline
23 & List.intersperse " | "
24 & Doc.toInline
25
26 instance Ord a => IsList (Ors a) where
27 type Item (Ors a) = a
28 fromList = Ors . fromList
29 toList = toList . unOrs
30
31 newtype Ands a = Ands {unAnds :: Set a}
32 deriving (Eq, Ord, Show, Generic)
33 deriving newtype (NFData)
34
35 instance Ord a => IsList (Ands a) where
36 type Item (Ands a) = a
37 fromList = Ands . fromList
38 toList = toList . unAnds
39
40 instance (Ord a, Doc.ToInline a) => Doc.ToInline (Ands a) where
41 toInline xs =
42 xs
43 & unAnds
44 & toList
45 <&> Doc.toInline
46 & List.intersperse " & "
47 & Doc.toInline
48
49 data Boolean a = BooleanTrue a | BooleanFalse a
50 deriving (Eq, Ord, Show, Generic, NFData)