Hi all,

Here's my attempt to convert a list of integers to a list of range tuples -

Given [1,2,3,6,8,9,10], I need [(1,3),(6,6),8,10)]

My attempt using foldl yields me the output in reverse. I can ofcourse
reverse the result, but what would be a better way?

f xs = foldl ff [] xs
        where
                []  `ff` i = [(i,i)]
                ((s,e):ns) `ff` i = if i == e+1 then
                                        (s,i):ns
                                        else
                                        (i,i):(s,e):ns

Regards,
Kashyap

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to