Copyright | © 2019 Vincent Archambault |
---|---|
License | 0BSD |
Maintainer | Vincent Archambault <archambault.v@gmail.com> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Definition of S-expression
Synopsis
- data SExpr b a
- type Sexp a = SExpr () a
- pattern A :: a -> SExpr b a
- pattern L :: [SExpr b a] -> SExpr b a
- pattern Sexp :: [Sexp a] -> Sexp a
- pattern (:::) :: SExpr b a -> SExpr b a -> SExpr b a
- pattern Nil :: SExpr b a
- isAtom :: SExpr b a -> Bool
- sAtom :: SExpr b a -> Maybe a
- isList :: SExpr b a -> Bool
- sList :: SExpr b a -> Maybe [SExpr b a]
Documentation
The datatype SExpr
is the definition of an S-expression for the
library S-expresso.
The parameter a
allows you to specify the datatype of atoms and
the parameter b
is usefull for keeping metadata about S-expression
like source position for example.
Instances
Functor (SExpr b) Source # | |
Foldable (SExpr b) Source # | |
Defined in Data.SExpresso.SExpr fold :: Monoid m => SExpr b m -> m # foldMap :: Monoid m => (a -> m) -> SExpr b a -> m # foldr :: (a -> b0 -> b0) -> b0 -> SExpr b a -> b0 # foldr' :: (a -> b0 -> b0) -> b0 -> SExpr b a -> b0 # foldl :: (b0 -> a -> b0) -> b0 -> SExpr b a -> b0 # foldl' :: (b0 -> a -> b0) -> b0 -> SExpr b a -> b0 # foldr1 :: (a -> a -> a) -> SExpr b a -> a # foldl1 :: (a -> a -> a) -> SExpr b a -> a # elem :: Eq a => a -> SExpr b a -> Bool # maximum :: Ord a => SExpr b a -> a # minimum :: Ord a => SExpr b a -> a # | |
Traversable (SExpr b) Source # | |
(Eq b, Eq a) => Eq (SExpr b a) Source # | |
(Show b, Show a) => Show (SExpr b a) Source # | |
pattern A :: a -> SExpr b a Source #
Shorthand for SAtom
.
foo (A x) = x -- Equivalent to foo (SAtom x) = x a = A 3 -- Equivalent to a = SAtom 3
pattern L :: [SExpr b a] -> SExpr b a Source #
Pattern for matching only the sublist of the SList
constructor.
See also the Sexp pattern synonym.
foo (L xs) = xs -- Equivalent to foo (SList _ xs) = xs
pattern (:::) :: SExpr b a -> SExpr b a -> SExpr b a infixr 5 Source #
Pattern specifying the shape of the sublist of the SList
constructor.
See also Nil
.
Although it aims to mimic the behavior of the cons (:) constructor
for list, this pattern behavior is a little bit different. Indeed
its signature is SExpr b a -> SExpr b a -> SExpr b a
while the
cons (:) constructor signature is a -> [a] -> [a]
. The first
argument type is different in the case of the cons constructor but all
the types are identical for the pattern :::
.
This implies that the following code
foo (x ::: xs) = ...
is equivalent to
foo (SList b (x : rest)) = let xs = SList b rest in ...
If you wish for the xs
above to match the remaining of the list,
you need to use the L
pattern
foo (A x ::: L xs)
which is equivalent to
foo (SList b (x : rest)) = let (SList _ xs) = SList b rest in ...
Other examples :
foo (A x1 ::: A x2 ::: Nil) -- Equivalent to foo (SList _ [SAtom x1, SAtom x2]) foo (L ys ::: A x ::: L xs) -- Equivalent to foo (SList _ (SList _ ys : SAtom x : xs))
pattern Nil :: SExpr b a Source #
Pattern to mark the end of the list when using the pattern synonym :::