# HG changeset patch # User Yasutaka Higa # Date 1404542362 -32400 # Node ID e96206b5d9c818b2c55295bc07b3b986fc9ca8dd Implement DiffList diff -r 000000000000 -r e96206b5d9c8 diffList.hs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/diffList.hs Sat Jul 05 15:39:22 2014 +0900 @@ -0,0 +1,34 @@ +-- Reflection without Remorse +-- http://homepages.cwi.nl/~ploeg/papers/zseq.pdf +-- https://github.com/atzeus/reflectionwithoutremorse + +-- try implement diff list + +type DiffList a = [a] -> [a] + +absFromDiffList :: DiffList a -> [a] -- original name = abs +absFromDiffList a = a [] + +rep :: [a] -> DiffList a +rep = (++) + +(+++) :: DiffList a -> DiffList a -> DiffList a +(+++) = (.) + +list = replicate 10000 'a' + +normalList = replicate 1000 list -- [l1, list2, list3, ..., listn] +diffList = map rep normalList -- [(++ list1), (++ list2), (++ list3), ..., (++ listn)] + +normalListLen = length $ foldl1 (++) normalList +-- length $ list1 ++ list2 ++ list3 ++ ... ++ listn +-- length $ ((list1 ++ list2) ++ list3) ++ ... ++ listn -- left associated + +diffListLen = length $ absFromDiffList $ foldl1 (+++) diffList +-- 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 ++ (...)))) ++ []