
Koen Claessen's "Parallel Parsing Processes," suggests their parsing combinators have been integrated into Parsec. If so, where is the +++ operator hiding? If not, does anyone know of a parsing library with a choice operator that does breadth-first search? Also, how do I determine what instances a datatype supports? Is Parsec an instance of Applicative? Thanks, Greg

garious:
Koen Claessen's "Parallel Parsing Processes," suggests their parsing combinators have been integrated into Parsec. If so, where is the +++ operator hiding?
Hoogle says: Control.Arrow.(+++) :: ArrowChoice a => a b c -> a b' c' -> a (Either b b') (Either c c') Text.Html.(+++) :: (HTML a, HTML b) => a -> b -> Html Text.ParserCombinators.ReadP.(+++) :: ReadP a -> ReadP a -> ReadP a Text.ParserCombinators.ReadPrec.(+++) :: ReadPrec a -> ReadPrec a -> ReadPrec a
Also, how do I determine what instances a datatype supports? Is Parsec an instance of Applicative?
Try :info on your type in ghci: Prelude Control.Applicative> :info Applicative class (Functor f) => Applicative f where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b -- Defined in Control.Applicative instance (Monad m) => Applicative (WrappedMonad m) -- Defined in Control.Applicative instance Applicative Maybe -- Defined in Control.Applicative instance Applicative [] -- Defined in Control.Applicative instance Applicative IO -- Defined in Control.Applicative instance Applicative ((->) a) -- Defined in Control.Applicative instance Applicative ZipList -- Defined in Control.Applicative -- Don

Text.ParserCombinators.ReadP.(+++) :: ReadP a -> ReadP a -> ReadP a
Wow, fast and complete, Thanks Don! :) Would it make sense to derive instances of Applicable and Alternative for ReadP? Something like this maybe: instance Applicative ReadP where pure = return (<*>) = ap instance Alternative ReadP where empty = pfail (<|>) = (<++) Thanks, Greg

A agreed upon technique for dealing with typeclass hierarchies has
been slow to arrive. For instance, all monads are functors, but
providing a monad instance for your type doesn't automatically make it
a functor as well.
All monads are also applicative functors, and Control.Applicative does
have a newtype to recognize them as such:
Prelude> :m + Control.Applicative
Prelude Control.Applicative> :i WrapMonad
newtype WrappedMonad m a = WrapMonad {unwrapMonad :: m a}
-- Defined in Control.Applicative
Prelude Control.Applicative> :i Applicative
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
-- Defined in Control.Applicative
instance (Monad m) => Applicative (WrappedMonad m)
-- Defined in Control.Applicative
...
Just "wrap" up your monad in WrapMonad, treat it like an applicative
functor, and then unwrap it with unwrapMonad.
HTH,
Nick
On 12/1/06, Greg Fitzgerald
Text.ParserCombinators.ReadP.(+++) :: ReadP a -> ReadP a -> ReadP a
Wow, fast and complete, Thanks Don! :)
Would it make sense to derive instances of Applicable and Alternative for ReadP? Something like this maybe:
instance Applicative ReadP where pure = return (<*>) = ap
instance Alternative ReadP where empty = pfail (<|>) = (<++)
Thanks, Greg _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
dons@cse.unsw.edu.au
-
Greg Fitzgerald
-
Nicolas Frisby