[Haskell-cafe] What's the new type ?
ryani.spam at gmail.com
Thu Nov 5 03:23:57 EST 2009
"newtype" creates a wrapper for an existing type that gets erased (so
it has no cost) at runtime, but is distinct during typechecking.
"type" creates an alias for an existing type, which is interchangeable
(so it doesn't really exist during typechecking).
In this case:
GenParser tok st a
is a function of the type
State tok st -> Consumed (Reply tok st a)
But you have to extract the value (via pattern matching) to call the
function; to the typechecker they are distinct types.
On the other hand, anywhere you see "Parser a", you could write
"GenParser Char () a" and it would work the same. It's just giving
you a shorter name for that common parser type.
On Wed, Nov 4, 2009 at 11:17 PM, 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 st
> 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: http://old.nabble.com/What%27s-the-new-type---tp26208600p26208600.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe