
28 Sep
2010
28 Sep
'10
11:20 a.m.
I think it is simpler to use the Maybe type for this. If you only search for ternary relations, you can write a function, which only converts a list to a 3-tuple if it is of length three and otherwise it returns nothing. Then with catMaybes :: [Maybe a] -> [a], you can convert it back to a list with only 3-tuples. import Data.Maybe getLengthThree = catMaybes . fmap toTup where toTup (x:y:z:[]) = Just (x,y,z) toTup _ = Nothing