
8 Mar
2010
8 Mar
'10
6:28 a.m.
Hi Magnus
That's not quite equivalent to Joe Fox's original code, although it is
an improvement as test in the original won't type check:
original...
test (DataConst1 x y) = x -- returns Int
test (DataConst2 x y) = x -- returns Int
test (DataConst3 x y) = y -- returns String
test (DataConst4 x y) = y -- returns Int
This one does type check...
test2 :: TestData -> Either Int String
test2 (DataConst1 x y) = Left x
test2 (DataConst2 x y) = Left x
test2 (DataConst3 x y) = Right y
test2 (DataConst4 x y) = Left y
On 8 March 2010 10:26, Magnus Therning
AFAICS the following would be equivalent to your code:
type TestData2 = (Either String Int, Either String Int) test2 (x@(Right _), _) = x test2 (Left _, y) = y