Hi Cafe!
Disclaimer: I know what I'm going to ask is now available as a language feature normally.
And sorry for the subject of this message, I couldn't compe up with a good&descriptive subject.
Is there any way to limit a functions type, not by a data type but by a group of constructors of a data type? If not, what would be the *right* thing to do to achieve this level of type safety?
data DT1 = X | Y | Z
data DT2 = A | B | C | D
func1 :: DT1 -> DT2 -- instead of this
func1' :: (X|Y) -> (B|C) -- i want sth. like this. (| means or)
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. But as you can imagine, this is not the only place I want to use this thing, and the code will start to look cryptic if I do so. I must add, I want to use this disjunction of constructors thingy in data type declerations as well.
A little bit brainstorming maybe?
Thanks in advance,
--
Ozgur Akgun