-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bool.hs
113 lines (91 loc) · 2.96 KB
/
Bool.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-----------------------------------------------------------------------------
-- |
-- Module : Generics.EMGM.Data.Bool
-- Copyright : (c) 2008, 2009 Universiteit Utrecht
-- License : BSD3
--
-- Maintainer : generics@haskell.org
-- Stability : experimental
-- Portability : non-portable
--
-- Summary: Generic representation and instances for 'Bool'.
-----------------------------------------------------------------------------
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
{- OPTIONS -ddump-splices -}
module Generics.EMGM.Data.Bool (
epBool,
conFalse,
conTrue,
repBool,
frepBool,
frep2Bool,
frep3Bool,
bifrep2Bool,
) where
import Generics.EMGM.Base
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere
-----------------------------------------------------------------------------
-- Embedding-projection pair
-----------------------------------------------------------------------------
fromBool :: Bool -> Unit :+: Unit
fromBool False = L Unit
fromBool True = R Unit
toBool :: Unit :+: Unit -> Bool
toBool (L Unit) = False
toBool (R Unit) = True
-- | Embedding-projection pair for 'Bool'.
epBool :: EP Bool (Unit :+: Unit)
epBool = EP fromBool toBool
-----------------------------------------------------------------------------
-- Representation values
-----------------------------------------------------------------------------
-- | Constructor description for 'False'.
conFalse :: ConDescr
conFalse = ConDescr "False" 0 False Prefix
-- | Constructor description for 'True'.
conTrue :: ConDescr
conTrue = ConDescr "True" 0 False Prefix
-- | Representation of 'Bool' for 'rep'.
repBool :: (Generic g) => g Bool
repBool =
rtype
epBool
(rcon conFalse runit `rsum` rcon conTrue runit)
-- | Representation of 'Bool' for 'frep'.
frepBool :: (Generic g) => g Bool
frepBool =
repBool
-- | Representation of 'Bool' for 'frep2'.
frep2Bool :: (Generic2 g) => g Bool Bool
frep2Bool =
rtype2
epBool epBool
(rcon2 conFalse runit2 `rsum2` rcon2 conTrue runit2)
-- | Representation of 'Bool' for 'frep3'.
frep3Bool :: (Generic3 g) => g Bool Bool Bool
frep3Bool =
rtype3
epBool epBool epBool
(rcon3 conFalse runit3 `rsum3` rcon3 conTrue runit3)
-- | Representation of 'Bool' for 'bifrep2'.
bifrep2Bool :: (Generic2 g) => g Bool Bool
bifrep2Bool =
frep2Bool
-----------------------------------------------------------------------------
-- Instance declarations
-----------------------------------------------------------------------------
instance (Generic g) => Rep g Bool where
rep = repBool
instance Rep (Collect Bool) Bool where
rep = Collect (:[])
instance Rep (Everywhere Bool) Bool where
rep = Everywhere ($)
instance Rep (Everywhere' Bool) Bool where
rep = Everywhere' ($)