- Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathRep.purs
62 lines (48 loc) · 1.92 KB
/
Rep.purs
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
moduleData.Generic.Rep
( classGeneric
, to
, from
, repOf
, NoConstructors
, NoArguments(..)
, Sum(..)
, Product(..)
, Constructor(..)
, Argument(..)
) where
importData.Semigroup ((<>))
importData.Show (classShow, show)
importData.Symbol (classIsSymbol, reflectSymbol)
importData.Void (Void)
importType.Proxy (Proxy(..))
-- | A representation for types with no constructors.
newtypeNoConstructors = NoConstructorsVoid
-- | A representation for constructors with no arguments.
dataNoArguments = NoArguments
instanceshowNoArguments :: ShowNoArgumentswhere
show _ = "NoArguments"
-- | A representation for types with multiple constructors.
dataSumab = Inla|Inrb
instanceshowSum :: (Showa, Showb) =>Show (Sumab) where
show (Inl a) = "(Inl " <> show a <> ")"
show (Inr b) = "(Inr " <> show b <> ")"
-- | A representation for constructors with multiple fields.
dataProductab = Productab
instanceshowProduct :: (Showa, Showb) =>Show (Productab) where
show (Product a b) = "(Product " <> show a <> "" <> show b <> ")"
-- | A representation for constructors which includes the data constructor name
-- | as a type-level string.
newtypeConstructor (name :: Symbol) a = Constructora
instanceshowConstructor :: (IsSymbolname, Showa) =>Show (Constructornamea) where
show (Constructor a) = "(Constructor @" <> show (reflectSymbol (Proxy::Proxyname)) <> "" <> show a <> ")"
-- | A representation for an argument in a data constructor.
newtypeArgumenta = Argumenta
instanceshowArgument :: Showa=>Show (Argumenta) where
show (Argument a) = "(Argument " <> show a <> ")"
-- | The `Generic` class asserts the existence of a type function from types
-- | to their representations using the type constructors defined in this module.
classGenericarep | a->repwhere
to::rep->a
from::a->rep
repOf::forallarep. Genericarep=>Proxya->Proxyrep
repOf _ = Proxy