changeset 0:e96206b5d9c8

Implement DiffList
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Sat, 05 Jul 2014 15:39:22 +0900
parents
children 0251da3f04f2
files diffList.hs
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 ++ (...)))) ++  []