Added docs for WellFormed cons/uncons
Getty Ritter
10 years ago
| 30 | 30 | import Control.Applicative ((<$>), (<*>), pure) |
| 31 | 31 | import Data.SCargot.Repr as R |
| 32 | 32 | |
| 33 | -- | Produce the head and tail of the s-expression (if possible). | |
| 34 | -- | |
| 35 | -- >>> uncons (L [A "el", A "eph", A "ant"]) | |
| 36 | -- Just (WFSAtom "el",WFSList [WFSAtom "eph",WFSAtom "ant"]) | |
| 33 | 37 | uncons :: WellFormedSExpr a -> Maybe (WellFormedSExpr a, WellFormedSExpr a) |
| 34 | 38 | uncons R.WFSAtom {} = Nothing |
| 35 | 39 | uncons (R.WFSList (x:xs)) = Just (x, R.WFSList xs) |
| 36 | 40 | |
| 41 | -- | Combine the two-expressions into a new one. This will return | |
| 42 | -- @Nothing@ if the resulting s-expression is not well-formed. | |
| 43 | -- | |
| 44 | -- >>> cons (A "el") (L [A "eph", A "ant"]) | |
| 45 | -- Just (WFSList [WFSAtom "el",WFSAtom "eph",WFSAtom "ant"]) | |
| 46 | -- >>> cons (A "pachy") (A "derm")) | |
| 47 | -- Nothing | |
| 37 | 48 | cons :: WellFormedSExpr a -> WellFormedSExpr a -> Maybe (WellFormedSExpr a) |
| 38 | 49 | cons _ (R.WFSAtom {}) = Nothing |
| 39 | 50 | cons x (R.WFSList xs) = Just (R.WFSList (x:xs)) |