[Haskell-cafe] Polymorphic algebraic type constructors

Tomasz Zielonka t.zielonka at students.mimuw.edu.pl
Tue Jun 22 07:38:21 EDT 2004


On Mon, Jun 21, 2004 at 06:03:21PM +0100, Graham Klyne wrote:
> If I have a polymorphic algebraic type (T a) with several type 
> constructors, only one of which actually references the type parameter, is 
> there any way to express type conversion for the type-parameter-independent 
> constructors without actually mentioning all the constructors?

One way to do this would be to use record update syntax, but you would
have to have the same field in all type-parameter-independent
constructors.

  data E a b
      = L1 { r :: a }
      | L2 { r :: a }
      | L3 { r :: a }
      | L4 { r :: a }
      | R b
      deriving Show

  f g (R a) = R (g a)
  f _ other = other { r = r other }

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links


More information about the Haskell-Cafe mailing list