gdritter repos s-cargot / 2d25c40
Fixed outstanding errors that appeared with -Wall: mostly adding type signatures to pattern synonyms Getty Ritter 8 years ago
4 changed file(s) with 24 addition(s) and 16 deletion(s). Collapse all Expand all
181181 pHead _ (SAtom a) = atomPrinter a
182182 pHead ind (SCons x xs) = gather ind x xs id
183183 gather ind h (SCons x xs) k = gather ind h xs (k . (x:))
184 gather ind h end k = "(" <> hd <> body <> tail <> ")"
185 where tail = case end of
184 gather ind h end k = "(" <> hd <> body <> tl <> ")"
185 where tl = case end of
186186 SNil -> ""
187187 SAtom a -> " . " <> atomPrinter a
188188 SCons _ _ -> error "[unreachable]"
7272 cons :: SExpr a -> SExpr a -> SExpr a
7373 cons = SCons
7474
75 mkList :: [SExpr a] -> SExpr a
76 mkList [] = SNil
77 mkList (x:xs) = SCons x (mkList xs)
78
79 mkDList :: [SExpr a] -> a -> SExpr a
80 mkDList [] a = SAtom a
81 mkDList (x:xs) a = SCons x (mkDList xs a)
82
8375 gatherDList :: SExpr a -> Maybe ([SExpr a], a)
8476 gatherDList SNil = Nothing
8577 gatherDList SAtom {} = Nothing
9688 --
9789 -- >>> A "pachy" ::: A "derm"
9890 -- SCons (SAtom "pachy") (SAtom "derm")
91 pattern (:::) :: SExpr a -> SExpr a -> SExpr a
9992 pattern x ::: xs = SCons x xs
10093
10194 -- | A shorter alias for `SAtom`
10295 --
10396 -- >>> A "elephant"
10497 -- SAtom "elephant"
98 pattern A :: a -> SExpr a
10599 pattern A x = SAtom x
106100
107101 -- | A (slightly) shorter alias for `SNil`
108102 --
109103 -- >>> Nil
110104 -- SNil
105 pattern Nil :: SExpr a
111106 pattern Nil = SNil
112107
113108 -- | An alias for matching a proper list.
114109 --
115110 -- >>> L [A "pachy", A "derm"]
116 -- SCons (SAtom "pachy") (SCons (SAtom "derm") SNil)
111 -- SExpr (SAtom "pachy") (SExpr (SAtom "derm") SNil)
112 pattern L :: [SExpr a] -> SExpr a
117113 pattern L xs <- (gatherList -> Right xs)
118114 #if MIN_VERSION_base(4,8,0)
119 where L xs = mkList xs
115 where L [] = SNil
116 L (x:xs) = SCons x (L xs)
120117 #endif
121118
122119
123120 -- | An alias for matching a dotted list.
124121 --
125122 -- >>> DL [A "pachy"] A "derm"
126 -- SCons (SAtom "pachy") (SAtom "derm")
123 -- SExpr (SAtom "pachy") (SAtom "derm")
124 pattern DL :: [SExpr a] -> a -> SExpr a
127125 pattern DL xs x <- (gatherDList -> Just (xs, x))
128126 #if MIN_VERSION_base(4,8,0)
129 where DL xs x = mkDList xs x
127 where DL [] a = SAtom a
128 DL (x:xs) a = SCons x (DL xs a)
130129 #endif
131130
132131 getShape :: SExpr a -> String
107107 --
108108 -- >>> A "one" ::: L [A "two", A "three"]
109109 -- RSList [RSAtom "one",RSAtom "two",RSAtom "three"]
110 pattern (:::) :: RichSExpr a -> RichSExpr a -> RichSExpr a
110111 pattern x ::: xs <- (uncons -> Just (x, xs))
111112 #if MIN_VERSION_base(4,8,0)
112113 where x ::: xs = cons x xs
116117 --
117118 -- >>> A "elephant"
118119 -- RSAtom "elephant"
119 pattern A a = R.RSAtom a
120 pattern A :: a -> RichSExpr a
121 pattern A a = R.RSAtom a
120122
121123 -- | A shorter alias for `RSList`
122124 --
123125 -- >>> L [A "pachy", A "derm"]
124126 -- RSList [RSAtom "pachy",RSAtom "derm"]
125 pattern L xs = R.RSList xs
127 pattern L :: [RichSExpr a] -> RichSExpr a
128 pattern L xs = R.RSList xs
126129
127130 -- | A shorter alias for `RSDotted`
128131 --
129132 -- >>> DL [A "pachy"] "derm"
130133 -- RSDotted [RSAtom "pachy"] "derm"
134 pattern DL :: [RichSExpr a] -> a -> RichSExpr a
131135 pattern DL xs x = R.RSDotted xs x
132136
133137 -- | A shorter alias for `RSList` @[]@
134138 --
135139 -- >>> Nil
136140 -- RSList []
141 pattern Nil :: RichSExpr a
137142 pattern Nil = R.RSList []
138143
139144 -- | Utility function for parsing a pair of things: this parses a two-element list,
5959 -- instead.
6060 --
6161 -- >>> let sum (x ::: xs) = x + sum xs; sum Nil = 0
62 pattern (:::) :: WellFormedSExpr a -> WellFormedSExpr a -> WellFormedSExpr a
6263 pattern x ::: xs <- (uncons -> Just (x, xs))
6364
6465 -- | A shorter alias for `WFSList`
6566 --
6667 -- >>> L [A "pachy", A "derm"]
6768 -- WFSList [WFSAtom "pachy",WFSAtom "derm"]
69 pattern L :: [WellFormedSExpr t] -> WellFormedSExpr t
6870 pattern L xs = R.WFSList xs
6971
7072 -- | A shorter alias for `WFSAtom`
7173 --
7274 -- >>> A "elephant"
7375 -- WFSAtom "elephant"
76 pattern A :: t -> WellFormedSExpr t
7477 pattern A a = R.WFSAtom a
7578
7679 -- | A shorter alias for `WFSList` @[]@
7780 --
7881 -- >>> Nil
7982 -- WFSList []
83 pattern Nil :: WellFormedSExpr t
8084 pattern Nil = R.WFSList []
8185
8286 getShape :: WellFormedSExpr a -> String