[Haskell-cafe] Question on definition of `parse' function in Parsec library.

Yves Parès limestrael at gmail.com
Sat Oct 8 19:15:39 CEST 2011


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-Parsec-Prim.html#t:Stream
)

ParsecT is the monad transformer, which when stacked with Identity gives a
simple monad, aliased by the type Parsec :
type Parsec s u =
ParsecT<http://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parsec-Prim.html#t:ParsecT>s
u
Identity<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Data-Functor-Identity.html#t:Identity>


2011/10/8 Yves Parès <limestrael at gmail.com>

> 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 <capn.freako at gmail.com>
>
>> 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 at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111008/57f144dd/attachment.htm>


More information about the Haskell-Cafe mailing list