Ver código fonte

Fixed outstanding errors that appeared with -Wall: mostly adding type signatures to pattern synonyms

Getty Ritter 8 anos atrás
pai
commit
2d25c40aa3

+ 2 - 2
Data/SCargot/Print.hs

@@ -181,8 +181,8 @@ prettyPrintSExpr SExprPrinter { .. } = pHead 0
         pHead _   (SAtom a)    = atomPrinter a
         pHead ind (SCons x xs) = gather ind x xs id
         gather ind h (SCons x xs) k = gather ind h xs (k . (x:))
-        gather ind h end          k = "(" <> hd <> body <> tail <> ")"
-          where tail = case end of
+        gather ind h end          k = "(" <> hd <> body <> tl <> ")"
+          where tl   = case end of
                          SNil      -> ""
                          SAtom a   -> " . " <> atomPrinter a
                          SCons _ _ -> error "[unreachable]"

+ 11 - 10
Data/SCargot/Repr/Basic.hs

@@ -72,14 +72,6 @@ uncons _            = Nothing
 cons :: SExpr a -> SExpr a -> SExpr a
 cons = SCons
 
-mkList :: [SExpr a] -> SExpr a
-mkList []     = SNil
-mkList (x:xs) = SCons x (mkList xs)
-
-mkDList :: [SExpr a] -> a -> SExpr a
-mkDList []     a = SAtom a
-mkDList (x:xs) a = SCons x (mkDList xs a)
-
 gatherDList :: SExpr a -> Maybe ([SExpr a], a)
 gatherDList SNil     = Nothing
 gatherDList SAtom {} = Nothing
@@ -96,37 +88,44 @@ infixr 5 :::
 --
 -- >>> A "pachy" ::: A "derm"
 -- SCons (SAtom "pachy") (SAtom "derm")
+pattern (:::) :: SExpr a -> SExpr a -> SExpr a
 pattern x ::: xs = SCons x xs
 
 -- | A shorter alias for `SAtom`
 --
 -- >>> A "elephant"
 -- SAtom "elephant"
+pattern A :: a -> SExpr a
 pattern A x = SAtom x
 
 -- | A (slightly) shorter alias for `SNil`
 --
 -- >>> Nil
 -- SNil
+pattern Nil :: SExpr a
 pattern Nil = SNil
 
 -- | An alias for matching a proper list.
 --
 -- >>> L [A "pachy", A "derm"]
+-- SExpr (SAtom "pachy") (SExpr (SAtom "derm") SNil)
+pattern L :: [SExpr a] -> SExpr a
 pattern L xs <- (gatherList -> Right xs)
 #if MIN_VERSION_base(4,8,0)
-  where L xs = mkList xs
+  where L []     = SNil
+        L (x:xs) = SCons x (L xs)
 #endif
 
 
 -- | An alias for matching a dotted list.
 --
 -- >>> DL [A "pachy"] A "derm"
+-- SExpr (SAtom "pachy") (SAtom "derm")
+pattern DL :: [SExpr a] -> a -> SExpr a
 pattern DL xs x <- (gatherDList -> Just (xs, x))
 #if MIN_VERSION_base(4,8,0)
-  where DL xs x = mkDList xs x
+  where DL []     a = SAtom a
+        DL (x:xs) a = SCons x (DL xs a)
 #endif
 
 getShape :: SExpr a -> String

+ 7 - 2
Data/SCargot/Repr/Rich.hs

@@ -107,6 +107,7 @@ cons x (R.RSAtom a)      = R.RSDotted [x] a
 --
 -- >>> A "one" ::: L [A "two", A "three"]
 -- RSList [RSAtom "one",RSAtom "two",RSAtom "three"]
+pattern (:::) :: RichSExpr a -> RichSExpr a -> RichSExpr a
 pattern x ::: xs <- (uncons -> Just (x, xs))
 #if MIN_VERSION_base(4,8,0)
   where x ::: xs = cons x xs
@@ -116,24 +117,28 @@ pattern x ::: xs <- (uncons -> Just (x, xs))
 --
 -- >>> A "elephant"
 -- RSAtom "elephant"
-pattern A a       = R.RSAtom a
+pattern A :: a -> RichSExpr a
+pattern A a = R.RSAtom a
 
 -- | A shorter alias for `RSList`
 --
 -- >>> L [A "pachy", A "derm"]
 -- RSList [RSAtom "pachy",RSAtom "derm"]
-pattern L xs      = R.RSList xs
+pattern L :: [RichSExpr a] -> RichSExpr a
+pattern L xs = R.RSList xs
 
 -- | A shorter alias for `RSDotted`
 --
 -- >>> DL [A "pachy"] "derm"
 -- RSDotted [RSAtom "pachy"] "derm"
+pattern DL :: [RichSExpr a] -> a -> RichSExpr a
 pattern DL xs x = R.RSDotted xs x
 
 -- | A shorter alias for `RSList` @[]@
 --
 -- >>> Nil
 -- RSList []
+pattern Nil :: RichSExpr a
 pattern Nil = R.RSList []
 
 -- | Utility function for parsing a pair of things: this parses a two-element list,

+ 4 - 0
Data/SCargot/Repr/WellFormed.hs

@@ -59,24 +59,28 @@ cons x (R.WFSList xs) = Just (R.WFSList (x:xs))
 --   instead.
 --
 -- >>> let sum (x ::: xs) = x + sum xs; sum Nil = 0
+pattern (:::) :: WellFormedSExpr a -> WellFormedSExpr a -> WellFormedSExpr a
 pattern x ::: xs <- (uncons -> Just (x, xs))
 
 -- | A shorter alias for `WFSList`
 --
 -- >>> L [A "pachy", A "derm"]
 -- WFSList [WFSAtom "pachy",WFSAtom "derm"]
+pattern L :: [WellFormedSExpr t] -> WellFormedSExpr t
 pattern L xs = R.WFSList xs
 
 -- | A shorter alias for `WFSAtom`
 --
 -- >>> A "elephant"
 -- WFSAtom "elephant"
+pattern A :: t -> WellFormedSExpr t
 pattern A a  = R.WFSAtom a
 
 -- | A shorter alias for `WFSList` @[]@
 --
 -- >>> Nil
 -- WFSList []
+pattern Nil :: WellFormedSExpr t
 pattern Nil = R.WFSList []
 
 getShape :: WellFormedSExpr a -> String