[Haskell-cafe] Strange typing?

Christoph Bier Christoph.Bier at gmx.de
Sun Mar 21 19:46:06 EDT 2010


> Only think I can think of is having the constructors, as seperate data
> types, introducing new type classes to group every possible subset of
> [X,Y,Z] and [A,B,C,D] and use those type classes when defining the
> functions. 

Wouldn't it be possible to use Either?
You make the constructors seperate data types and then have something

> func1 :: Either X Y -> Either B C

When you need more then two alternatives you could define similar
datatypes like

> OneOfThree x y z = OOTFirst x | OOTSecond y | OOTThird z

or something like

> {-# LANGUAGE TypeOperators #-}
> data Or x y = First x | Second y deriving (Show)
> infixl 5 `Or`

> func :: Int `Or` String `Or` Integer -> String `Or` Integer

but then pattern matching becomes ugly.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100321/c5f1e3a8/attachment.bin

More information about the Haskell-Cafe mailing list