Browse Source

Shortened/diversified pattern aliases

Getty Ritter 10 years ago
parent
commit
d60633fae1
3 changed files with 49 additions and 10 deletions
  1. 13 0
      Data/SCargot/Repr/Basic.hs
  2. 20 6
      Data/SCargot/Repr/Rich.hs
  3. 16 4
      Data/SCargot/Repr/WellFormed.hs

+ 13 - 0
Data/SCargot/Repr/Basic.hs

@@ -3,6 +3,19 @@
 module Data.SCargot.Repr.Basic
        ( -- * Basic 'SExpr' representation
          R.SExpr(..)
+         -- * Shorthand Patterns
+       , pattern (:::)
+       , pattern A
+       , pattern Nil
        ) where
 
 import Data.SCargot.Repr as R
+
+-- | A shorter infix alias for `SCons`
+pattern x ::: xs = SCons x xs
+
+-- | A shorter alias for `SAtom`
+pattern A x = SAtom x
+
+-- | A (slightly) shorter alias for `SNil`
+pattern Nil = SNil

+ 20 - 6
Data/SCargot/Repr/Rich.hs

@@ -6,13 +6,27 @@ module Data.SCargot.Repr.Rich
        , R.toRich
        , R.fromRich
          -- * Useful pattern synonyms
-       , pattern List
-       , pattern DotList
-       , pattern Atom
+       , pattern (:::)
+       , pattern A
+       , pattern L
+       , pattern DL
+       , pattern Nil
        ) where
 
 import Data.SCargot.Repr as R
 
-pattern Atom a       = R.RSAtom a
-pattern List xs      = R.RSList xs
-pattern DotList xs x = R.RSDotted xs x
+-- | A shorter infix alias to grab the head
+--   and tail of an `RSList`.
+pattern x ::: xs = R.RSList (x : xs)
+
+-- | A shorter alias for `RSAtom`
+pattern A a       = R.RSAtom a
+
+-- | A shorter alias for `RSList`
+pattern L xs      = R.RSList xs
+
+-- | A shorter alias for `RSDotted`
+pattern DL xs x = R.RSDotted xs x
+
+-- | A shorter alias for `RSList []`
+pattern Nil = R.RSList []

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

@@ -6,11 +6,23 @@ module Data.SCargot.Repr.WellFormed
        , R.toWellFormed
        , R.fromWellFormed
          -- * Useful pattern synonyms
-       , pattern List
-       , pattern Atom
+       , pattern (:::)
+       , pattern L
+       , pattern A
+       , pattern Nil
        ) where
 
 import Data.SCargot.Repr as R
 
-pattern List xs = R.WFSList xs
-pattern Atom a  = R.WFSAtom a
+-- | A shorter infix alias to grab the head
+--   and tail of a `WFSList`
+pattern x ::: xs = R.WFSList (x : xs)
+
+-- | A shorter alias for `WFSList`
+pattern L xs = R.WFSList xs
+
+-- | A shorter alias for `WFSAtom`
+pattern A a  = R.WFSAtom a
+
+-- | A shorter alias for `WFSList []`
+pattern Nil = R.WFSList []