Fixed outstanding errors that appeared with -Wall: mostly adding type signatures to pattern synonyms
Getty Ritter
9 years ago
| 181 | 181 | pHead _ (SAtom a) = atomPrinter a |
| 182 | 182 | pHead ind (SCons x xs) = gather ind x xs id |
| 183 | 183 | 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 | |
| 186 | 186 | SNil -> "" |
| 187 | 187 | SAtom a -> " . " <> atomPrinter a |
| 188 | 188 | SCons _ _ -> error "[unreachable]" |
| 72 | 72 | cons :: SExpr a -> SExpr a -> SExpr a |
| 73 | 73 | cons = SCons |
| 74 | 74 | |
| 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 | ||
| 83 | 75 | gatherDList :: SExpr a -> Maybe ([SExpr a], a) |
| 84 | 76 | gatherDList SNil = Nothing |
| 85 | 77 | gatherDList SAtom {} = Nothing |
| 96 | 88 | -- |
| 97 | 89 | -- >>> A "pachy" ::: A "derm" |
| 98 | 90 | -- SCons (SAtom "pachy") (SAtom "derm") |
| 91 | pattern (:::) :: SExpr a -> SExpr a -> SExpr a | |
| 99 | 92 | pattern x ::: xs = SCons x xs |
| 100 | 93 | |
| 101 | 94 | -- | A shorter alias for `SAtom` |
| 102 | 95 | -- |
| 103 | 96 | -- >>> A "elephant" |
| 104 | 97 | -- SAtom "elephant" |
| 98 | pattern A :: a -> SExpr a | |
| 105 | 99 | pattern A x = SAtom x |
| 106 | 100 | |
| 107 | 101 | -- | A (slightly) shorter alias for `SNil` |
| 108 | 102 | -- |
| 109 | 103 | -- >>> Nil |
| 110 | 104 | -- SNil |
| 105 | pattern Nil :: SExpr a | |
| 111 | 106 | pattern Nil = SNil |
| 112 | 107 | |
| 113 | 108 | -- | An alias for matching a proper list. |
| 114 | 109 | -- |
| 115 | 110 | -- >>> L [A "pachy", A "derm"] |
| 116 |
-- S |
|
| 111 | -- SExpr (SAtom "pachy") (SExpr (SAtom "derm") SNil) | |
| 112 | pattern L :: [SExpr a] -> SExpr a | |
| 117 | 113 | pattern L xs <- (gatherList -> Right xs) |
| 118 | 114 | #if MIN_VERSION_base(4,8,0) |
| 119 |
where L |
|
| 115 | where L [] = SNil | |
| 116 | L (x:xs) = SCons x (L xs) | |
| 120 | 117 | #endif |
| 121 | 118 | |
| 122 | 119 | |
| 123 | 120 | -- | An alias for matching a dotted list. |
| 124 | 121 | -- |
| 125 | 122 | -- >>> DL [A "pachy"] A "derm" |
| 126 |
-- S |
|
| 123 | -- SExpr (SAtom "pachy") (SAtom "derm") | |
| 124 | pattern DL :: [SExpr a] -> a -> SExpr a | |
| 127 | 125 | pattern DL xs x <- (gatherDList -> Just (xs, x)) |
| 128 | 126 | #if MIN_VERSION_base(4,8,0) |
| 129 |
where DL |
|
| 127 | where DL [] a = SAtom a | |
| 128 | DL (x:xs) a = SCons x (DL xs a) | |
| 130 | 129 | #endif |
| 131 | 130 | |
| 132 | 131 | getShape :: SExpr a -> String |
| 107 | 107 | -- |
| 108 | 108 | -- >>> A "one" ::: L [A "two", A "three"] |
| 109 | 109 | -- RSList [RSAtom "one",RSAtom "two",RSAtom "three"] |
| 110 | pattern (:::) :: RichSExpr a -> RichSExpr a -> RichSExpr a | |
| 110 | 111 | pattern x ::: xs <- (uncons -> Just (x, xs)) |
| 111 | 112 | #if MIN_VERSION_base(4,8,0) |
| 112 | 113 | where x ::: xs = cons x xs |
| 116 | 117 | -- |
| 117 | 118 | -- >>> A "elephant" |
| 118 | 119 | -- RSAtom "elephant" |
| 119 |
pattern A |
|
| 120 | pattern A :: a -> RichSExpr a | |
| 121 | pattern A a = R.RSAtom a | |
| 120 | 122 | |
| 121 | 123 | -- | A shorter alias for `RSList` |
| 122 | 124 | -- |
| 123 | 125 | -- >>> L [A "pachy", A "derm"] |
| 124 | 126 | -- RSList [RSAtom "pachy",RSAtom "derm"] |
| 125 |
pattern L |
|
| 127 | pattern L :: [RichSExpr a] -> RichSExpr a | |
| 128 | pattern L xs = R.RSList xs | |
| 126 | 129 | |
| 127 | 130 | -- | A shorter alias for `RSDotted` |
| 128 | 131 | -- |
| 129 | 132 | -- >>> DL [A "pachy"] "derm" |
| 130 | 133 | -- RSDotted [RSAtom "pachy"] "derm" |
| 134 | pattern DL :: [RichSExpr a] -> a -> RichSExpr a | |
| 131 | 135 | pattern DL xs x = R.RSDotted xs x |
| 132 | 136 | |
| 133 | 137 | -- | A shorter alias for `RSList` @[]@ |
| 134 | 138 | -- |
| 135 | 139 | -- >>> Nil |
| 136 | 140 | -- RSList [] |
| 141 | pattern Nil :: RichSExpr a | |
| 137 | 142 | pattern Nil = R.RSList [] |
| 138 | 143 | |
| 139 | 144 | -- | Utility function for parsing a pair of things: this parses a two-element list, |
| 59 | 59 | -- instead. |
| 60 | 60 | -- |
| 61 | 61 | -- >>> let sum (x ::: xs) = x + sum xs; sum Nil = 0 |
| 62 | pattern (:::) :: WellFormedSExpr a -> WellFormedSExpr a -> WellFormedSExpr a | |
| 62 | 63 | pattern x ::: xs <- (uncons -> Just (x, xs)) |
| 63 | 64 | |
| 64 | 65 | -- | A shorter alias for `WFSList` |
| 65 | 66 | -- |
| 66 | 67 | -- >>> L [A "pachy", A "derm"] |
| 67 | 68 | -- WFSList [WFSAtom "pachy",WFSAtom "derm"] |
| 69 | pattern L :: [WellFormedSExpr t] -> WellFormedSExpr t | |
| 68 | 70 | pattern L xs = R.WFSList xs |
| 69 | 71 | |
| 70 | 72 | -- | A shorter alias for `WFSAtom` |
| 71 | 73 | -- |
| 72 | 74 | -- >>> A "elephant" |
| 73 | 75 | -- WFSAtom "elephant" |
| 76 | pattern A :: t -> WellFormedSExpr t | |
| 74 | 77 | pattern A a = R.WFSAtom a |
| 75 | 78 | |
| 76 | 79 | -- | A shorter alias for `WFSList` @[]@ |
| 77 | 80 | -- |
| 78 | 81 | -- >>> Nil |
| 79 | 82 | -- WFSList [] |
| 83 | pattern Nil :: WellFormedSExpr t | |
| 80 | 84 | pattern Nil = R.WFSList [] |
| 81 | 85 | |
| 82 | 86 | getShape :: WellFormedSExpr a -> String |