[Haskell-cafe] Polymorphic algebraic type constructors
Tomasz Zielonka
t.zielonka at students.mimuw.edu.pl
Tue Jun 22 08:52:21 EDT 2004
On Tue, Jun 22, 2004 at 01:29:02PM +0100, MR K P SCHUPKE wrote:
> >data E a b
> > = L1 { r :: a }
> > | L2 { r :: a }
> > | L3 { r :: a }
> > | L4 { r :: a }
> > | R b
> > deriving Show
>
> How is this different from:
>
> data E a b = L1 a | L2 a | R b
>
> f g (R a) = R (g a)
> f _ other = other
> Isn't this more or less what was in the original...
Nope. My f has type
(b -> b1) -> E a b -> E a b1
> The problem is the type:
>
> f :: (a->b) -> Either String a -> Either String b
>
> this line: f _ other = other
>
> says: Either String a == Either String b -- which it doesn't
Record update avoids this because of the way it is translated.
Basically, the result of record update is a reconstructed record, but
constructors not containing updated fields are not built/copied, so they
don't constrain the resulting type. See Haskell 98 Report for details.
Anyway, I doubt the OP can benefit from it.
> Keean.
Best regards,
Tom
--
.signature: Too many levels of symbolic links
More information about the Haskell-Cafe
mailing list