# HG changeset patch
# User Yasutaka Higa
# Date 1416187418 32400
# Node ID d654fdecdcd034c69d464cd8d12b4a2cc042c83a
# Parent 820af7cc848595e6a3e7aa18dbb3b5ff9ec779d1
Wrote bubble sort with modified calculate
diff r 820af7cc8485 r d654fdecdcd0 delta.hs
 a/delta.hs Mon Nov 17 10:10:25 2014 +0900
+++ b/delta.hs Mon Nov 17 10:23:38 2014 +0900
@@ 26,16 +26,8 @@
instance Functor Delta where
fmap f (Delta xs x ys y) = Delta xs (f x) ys (f y)
 not proof
fmapS :: (Show a) => (a > b) > Delta a > Delta b
fmapS f (Delta lx x ly y) = Delta (lx ++ [(show x)]) (f x) (ly ++ [(show y)]) (f y)

 not proof
fmapSS :: (Show a) => (a > b) > (a > b) > Delta a > Delta b
fmapSS f g (Delta lx x ly y) = Delta (lx ++ [(show x)]) (f x) (ly ++ [(show y)]) (g y)

instance Applicative Delta where
 pure f = Delta [] f [] f
+ pure f = Delta [] f [] f
(Delta lf f lg g) <*> (Delta lx x ly y) = Delta (lf ++ lx) (f x) (lg ++ ly) (g y)
mu :: Delta (Delta a) > Delta a
@@ 72,7 +64,10 @@
bubbleSort :: [Int] > Delta [Int]
bubbleSort [] = returnS []
bubbleSort xs = bubbleSort remainValue >>= (\xs > returnS $ sortedValue : xs)
+bubbleSort xs = bubbleSort remainValue >>= (\xs > returnSS (sortedValueL : xs)
+ (sortedValueR ++ xs))
where
 sortedValue = maximum xs
 remainValue = filter (/= sortedValue) xs
+ maxmumValue = maximum xs
+ sortedValueL = maxmumValue
+ sortedValueR = replicate (length $ filter (== maxmumValue) xs) maxmumValue
+ remainValue = filter (/= maxmumValue) xs