changeset 1:0251da3f04f2

Add foldr version
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Sat, 05 Jul 2014 16:11:34 +0900
parents e96206b5d9c8
children eccc7eced616
files diffList.hs
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/diffList.hs	Sat Jul 05 15:39:22 2014 +0900
+++ b/diffList.hs	Sat Jul 05 16:11:34 2014 +0900
@@ -20,15 +20,25 @@
 normalList = replicate 1000 list -- [l1, list2, list3, ..., listn]
 diffList   = map rep normalList  -- [(++ list1), (++ list2), (++ list3), ..., (++ listn)]
 
-normalListLen = length $ foldl1 (++) normalList
+normalListLeftLength = length $ foldl1 (++) normalList
 -- length $ list1 ++ list2 ++ list3 ++ ... ++ listn
 -- length $ ((list1 ++ list2) ++ list3) ++ ... ++ listn -- left associated
+--
+normalListRightLength = length $ foldr1 (++) normalList
+-- length $ list1 ++ list2 ++ list3 ++ ... ++ listn
+-- length $ (list1 ++ (list2 ++ (list3 ++ ... ++ listn))) -- right associated
 
-diffListLen   = length $ absFromDiffList $ foldl1 (+++) diffList
+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 ++ (...)))))
 -- length $ (++ (list1 ++ (list2 ++ (list3 ++ (...))))) []
 -- length $ (list1 ++ (list2 ++ (list3 ++ (...)))) ++  [] -- right associated
 -- length $ (list1 ++ (list2 ++ (list3 ++ (...)))) ++  []
+
+
+-- normalListRightLength -- ok
+-- normalListLeftLength  -- slowly
+-- diffListLeftLength    -- ok