Safe Haskell | None |
---|---|
Language | Haskell98 |
- data SymbParser b
- data IMParser b
- class HasAlts a where
- class IsSymbParser a where
- toSymb :: a b -> SymbParser b
- class IsIMParser a where
- parse :: IsSymbParser s => s a -> [Token] -> IO [a]
- parseString :: IsSymbParser s => s a -> String -> IO [a]
- char :: Char -> SymbParser Char
- token :: Token -> SymbParser Token
- data Token
- epsilon :: SymbParser ()
- satisfy :: a -> IMParser a
- many :: SymbParser a -> SymbParser [a]
- some :: SymbParser a -> SymbParser [a]
- optional :: SymbParser a -> SymbParser (Maybe a)
- (<::=>) :: HasAlts b => String -> b a -> SymbParser a
- (<:=>) :: HasAlts b => String -> b a -> SymbParser a
- (<$>) :: IsSymbParser s => (a -> b) -> s a -> IMParser b
- (<$) :: IsSymbParser s => b -> s a -> IMParser b
- (<*>) :: (IsIMParser i, IsSymbParser s) => i (a -> b) -> s a -> IMParser b
- (<*) :: (IsIMParser i, IsSymbParser s) => i b -> s a -> IMParser b
- (<|>) :: (IsIMParser i, HasAlts b) => i a -> b a -> ([] :. IMParser) a
- data (g :. f) a :: (* -> *) -> (* -> *) -> * -> *
- memo :: IsSymbParser s => MemoRef [a] -> s a -> SymbParser a
- newMemoTable :: IO (MemoRef a)
- type MemoRef a = IORef (MemoTable a)
- type MemoTable a = IntMap (IntMap a)
Documentation
class IsSymbParser a where Source
toSymb :: a b -> SymbParser b Source
class IsIMParser a where Source
parse :: IsSymbParser s => s a -> [Token] -> IO [a] Source
The semantic results of a parser, given a string of Tokens
parseString :: IsSymbParser s => s a -> String -> IO [a] Source
Parse a string of characters
char :: Char -> SymbParser Char Source
token :: Token -> SymbParser Token Source
epsilon :: SymbParser () Source
many :: SymbParser a -> SymbParser [a] Source
some :: SymbParser a -> SymbParser [a] Source
optional :: SymbParser a -> SymbParser (Maybe a) Source
(<::=>) :: HasAlts b => String -> b a -> SymbParser a infixl 2 Source
Use this combinator on all combinators that might have an infinite number of derivations for some input string. A non-terminal has this property if and only if it is left-recursive and would be left-recursive if all the right-hand sides of the productions of the grammar are reversed.
(<:=>) :: HasAlts b => String -> b a -> SymbParser a infixl 2 Source
Use this combinator on all recursive non-terminals
(<$>) :: IsSymbParser s => (a -> b) -> s a -> IMParser b infixl 4 Source
(<$) :: IsSymbParser s => b -> s a -> IMParser b infixl 4 Source
(<*>) :: (IsIMParser i, IsSymbParser s) => i (a -> b) -> s a -> IMParser b infixl 4 Source
(<*) :: (IsIMParser i, IsSymbParser s) => i b -> s a -> IMParser b infixl 4 Source
data (g :. f) a :: (* -> *) -> (* -> *) -> * -> * infixl 9
Composition of unary type constructors
There are (at least) two useful Monoid
instances, so you'll have to
pick one and type-specialize it (filling in all or parts of g
and/or f
).
-- standard Monoid instance for Applicative applied to Monoid instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where { mempty = pure mempty; mappend = liftA2 mappend } -- Especially handy when g is a Monoid_f. instance Monoid (g (f a)) => Monoid ((g :. f) a) where { mempty = O mempty; mappend = inO2 mappend }
Corresponding to the first and second definitions above,
instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) } instance Monoid_f g => Monoid_f (g :. f) where { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }
Similarly, there are two useful Functor
instances and two useful
ContraFunctor
instances.
instance ( Functor g, Functor f) => Functor (g :. f) where fmap = fmapFF instance (ContraFunctor g, ContraFunctor f) => Functor (g :. f) where fmap = fmapCC instance ( Functor g, ContraFunctor f) => ContraFunctor (g :. f) where contraFmap = contraFmapFC instance (ContraFunctor g, Functor f) => ContraFunctor (g :. f) where contraFmap = contraFmapCF
However, it's such a bother to define the Functor instances per composition type, I've left the fmapFF case in. If you want the fmapCC one, you're out of luck for now. I'd love to hear a good solution. Maybe someday Haskell will do Prolog-style search for instances, subgoaling the constraints, rather than just matching instance heads.
(Functor g, Functor f) => Functor ((:.) g f) | |
(Applicative g, Applicative f) => Applicative ((:.) g f) | |
(Foldable g, Foldable f, Functor g) => Foldable ((:.) g f) | |
(Traversable g, Traversable f) => Traversable ((:.) g f) | |
IsSymbParser ((:.) [] IMParser) | |
IsIMParser ((:.) [] IMParser) | |
HasAlts ((:.) [] IMParser) | |
IsSymbParser ((:.) [] IMParser) | |
IsIMParser ((:.) [] IMParser) | |
HasAlts ((:.) [] IMParser) | |
Eq (g (f a)) => Eq ((:.) g f a) | |
Show (g (f a)) => Show ((:.) g f a) |
memo :: IsSymbParser s => MemoRef [a] -> s a -> SymbParser a Source
newMemoTable :: IO (MemoRef a) Source