# HG changeset patch # User Yasutaka Higa # Date 1404554899 -32400 # Node ID eccc7eced6164e71673c201c8a9f7ba7d7d44e67 # Parent 0251da3f04f2a9963598b36067bc06e25a4a2b44 Add foldr style diffList diff -r 0251da3f04f2 -r eccc7eced616 diffList.hs --- a/diffList.hs Sat Jul 05 16:11:34 2014 +0900 +++ b/diffList.hs Sat Jul 05 19:08:19 2014 +0900 @@ -31,14 +31,22 @@ diffListLeftLength = length $ absFromDiffList $ foldl1 (+++) diffList -- length $ absFromDiffList $ (++ list1) +++ (++ list2) +++ (++ list3) +++ ... +++ (++ listn) -- length $ absFromDiffList $ (((++ list1) +++ (++ list2)) +++ (++ list3)) +++ ... +++ (++ listn) --- length $ absFromDiffList $ (++ list1) . (++ list2) . (++ list3) . ... . (++ listn) --- length $ absFromDiffList $ (++ list1) . (++ list2) . (++ list3) . ... . (++ listn) -- (++ list1) = \x -> list1 ++ x +-- length $ absFromDiffList $ ((((++ list1) . (++ list2)) . (++ list3)) . ... . (++ listn) -- (++ list1)) = \x -> list1 ++ x -- length $ absFromDiffList $ (++ (list1 ++ (list2 ++ (list3 ++ (...))))) -- length $ (++ (list1 ++ (list2 ++ (list3 ++ (...))))) [] --- length $ (list1 ++ (list2 ++ (list3 ++ (...)))) ++ [] -- right associated -- length $ (list1 ++ (list2 ++ (list3 ++ (...)))) ++ [] +-- length $ ((list1 ++ (list2 ++ (list3 ++ (...)))) ++ []) -- right associated + +diffListRightLength = length $ absFromDiffList $ foldr1 (+++) diffList +-- length $ absFromDiffList $ (++ list1) +++ (++ list2) +++ (++ list3) +++ ... +++ (++ listn) +-- length $ absFromDiffList $ ((++ list1) +++ ((++ list2) +++ ((++ list3) +++ ... +++ (++ listn)))) +-- length $ absFromDiffList $ ((++ list1) . ((++ list2) . ((++ list3) . ... . (++ listn)))) +-- length $ absFromDiffList $ (++ (list1 ++ (list2 ++ (list3 ++ (...))))) +-- length $ (++ (list1 ++ (list2 ++ (list3 ++ (...))))) [] +-- length $ ((list1 ++ (list2 ++ (list3 ++ (...)))) ++ []) -- right associated -- normalListRightLength -- ok -- normalListLeftLength -- slowly -- diffListLeftLength -- ok +-- diffListRightLength -- ok