
22 Mar
2010
22 Mar
'10
5:32 a.m.
Ozgur Akgun wrote:
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)
OCaml has a feature called 'polymorphic variants' that allows exactly this. You may want to google 'polymorphic variants in haskell'.