[Haskell-cafe] an advanced foldification problem

Seth Gordon sethg at ropine.com
Thu Jan 11 12:37:23 EST 2007


I have a data type "Group", representing a group of geographic
information that is all referring to the same location, and a function
"mergeGroups" that tries to merge two groups:

    mergeGroups :: Group -> Group -> Maybe Group

Then I have a function "mergeGroupToList" that tries to merge its first
argument with every element of the second argument:

    mergeGroupToList :: Group -> [Group] -> [Group]
    mergeGroupToList g [] = [g]
    mergeGroupToList g1 (g2:gs) =
        case (mergeGroups g1 g2) of
        Nothing -> g2 : (mergeGroupToList g1 gs)
        Just g3 -> mergeGroupToList g3 gs

How can I rewrite mergeGroupToList in terms of foldr?


More information about the Haskell-Cafe mailing list