view diffList.hs @ 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
line wrap: on
line source

-- 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 ++ (...)))) ++  []