[Haskell-cafe] What's the new type ?
z_axis at 163.com
Fri Nov 6 19:53:00 EST 2009
very clear ! thank you
> Given a newtype declaration:
> newtype Foo a = Bar (...)
> The newtype is Foo a, and it uses a constructor Bar, which gets 'erased'
> compile time, unlike a data declaration. By convention, usually Foo and
> are the same thing. In this case the constructor for GenParser is named
> Parser instead.
> To understand the GenParser type, you must consider that originally,
> 'GenParser' probably didn't exist. And if it did, there is a pedagogical
> justification to just explaining the simpler 'Parser' case first without
> appealing to the notion of a parser in its full generality.
> So if you started from a type like
> newtype Parser a = Parser (State Char () -> Consumed (Reply Char () a))
> and later want to generalize that to a more permissive signature, without
> breaking all of the code that uses that constructor, then the upgrade path
> for that code is to keep the same constructor name, but generalize the
> So Parser becomes a type alias:
> type Parser = GenParser Char ()
> and GenParser is introduced as a newtype, which happens to use the
> constructor Parser for the dual reasons of backwards compatibility and so
> that people working on simple parsers don't need to think about
> user state and token types.
> newtype GenParser tok st a = Parser (State tok st -> Consumed (Reply tok
> Now the only thing that breaks is that any code that previously defined
> instances for Parser before the notion of GenParser must add a LANGUAGE
> pragma indicating that TypeSynonymInstances are allowed.
> -Edward Kmett
> On Thu, Nov 5, 2009 at 2:17 AM, zaxis <z_axis at 163.com> wrote:
>> type Parser a = GenParser Char () a
>> newtype GenParser tok st a = Parser (State tok st -> Consumed (Reply tok
>> As i know, the Parser type is just an alias of GenParser. Then can the
>> second line be replaced as below?
>> newtype GenParser tok st a = GenParser Char () (State tok st -> Consumed
>> (Reply tok st a))
>> If it can , then what is the new type ?
>> fac n = foldr (*) 1 [1..n]
>> View this message in context:
>> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
fac n = foldr (*) 1 [1..n]
View this message in context: http://old.nabble.com/What%27s-the-new-type---tp26208600p26233954.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe