Question on definition of `parse' function in Parsec library.

Hi all, In this definition from the Parsec library: parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError aparse p = runP p () what's the significance of `Identity t'? (`t' isn't used anywhere.) Thanks, -db

If I have this right, Stream is a monad transformer.
Stream s m t means that it parses 's', is stacked with monad 'm' and has a
result of type 't'
So Identity is a monad, the simplest monad, defined as such:
newtype Indentity t = Identity { runIdentity :: t }
It's the identity monad, that does nothing special but wrapping its result.
2011/10/8 Captain Freako
Hi all,
In this definition from the Parsec library:
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError aparse p = runP p ()
what's the significance of `Identity t'? (`t' isn't used anywhere.)
Thanks, -db
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Wow... my bad. Stream is in no way a monad transformer.
I really should read before speaking...
Stream s m t is such as "An instance of Stream has stream type s, underlying
monad m and token type t determined by the stream" (
http://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parse...
)
ParsecT is the monad transformer, which when stacked with Identity gives a
simple monad, aliased by the type Parsec :
type Parsec s u =
ParsecThttp://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parse...s
u
Identityhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Da...
2011/10/8 Yves Parès
If I have this right, Stream is a monad transformer. Stream s m t means that it parses 's', is stacked with monad 'm' and has a result of type 't'
So Identity is a monad, the simplest monad, defined as such:
newtype Indentity t = Identity { runIdentity :: t }
It's the identity monad, that does nothing special but wrapping its result.
2011/10/8 Captain Freako
Hi all,
In this definition from the Parsec library:
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError aparse p = runP p ()
what's the significance of `Identity t'? (`t' isn't used anywhere.)
Thanks, -db
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Am 08.10.2011 16:04, schrieb Captain Freako:
Hi all,
In this definition from the Parsec library:
parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError a parse p = runP p ()
what's the significance of `Identity t'? (`t' isn't used anywhere.)
http://hackage.haskell.org/packages/archive/parsec/3.1.2/doc/html/Text-Parse... Text.Parsec.Prim contains class Monad m => Stream s m t | s -> t where saying that the type s determines t (that is a functional dependency). The instances are: Monad m => Stream ByteString m Char Monad m => Stream ByteString m Char Monad m => Stream Text m Char Monad m => Stream Text m Char Monad m => Stream [tok] m tok so usually you have a character stream. (There are lazy and strict version of Text and ByteString.) The last instance also works for plain strings (String = [Char]). Using "Identity" for the monad m just means, that you actually do not need a monad (but need to supply a dummy one). If you want to keep thinks simpler you could use packages parsec1 or parsec2 Cheers Christian http://hackage.haskell.org/package/parsec2 http://hackage.haskell.org/package/parsec1
Thanks, -db
participants (3)
-
Captain Freako
-
Christian Maeder
-
Yves Parès