= go [] xs where go ys [] = ys go ys (x:xs) = go (insert x ys) xs insert :: Int -> [Int] -> [Int] insert x ys = xs ++ [x] ++ zs where (xs, zs) = span (<= x) ys
-> b -> [a] -> b foldr _ z [] = z foldr k z (y:ys) = y `k` foldr k z ys insertSort :: [Int] -> [Int] insertSort = foldr insert [] ࣮ͷ࠶ؼతͳߏΛGPMESΛͬͯ 3FDVSTJPO4DIFNFT
-> [Int] toList (In Nil) = [] toList (In (Cons x xs)) = x : toList xs fromList :: [Int] -> Fix List fromList [] = In Nil fromList (x:xs) = In $ Cons x (fromList xs)
(Cons 6 (In (Cons 5 (In (Cons 2 (In Nil)…) ana f (Cons 1 (ana f (Cons 6 (ana f (Cons 5 (ana f (Cons 2 (ana f Nil)…) ana f (Cons 1 (ana f (Cons 6 (ana f (Cons 5 (In (Cons’ 2 (In Nil’))…) cata - ana - swap DBUBશͯͷ*OΛஔ͖͑Δ ͜͜·ͰධՁ͢Δ ͜ΕιʔτࡁΈͷϦετ
. fmap out) (Cons 5 (In (Cons’ 2 (In Nil’))…) ana f (Cons 1 (ana f (Cons 6 (In . fmap (ana f) $ swap (Cons 5 (Cons’ 2 (In Nil’))…) ana f (Cons 1 (ana f (Cons 6 (In (Cons’ 2 (ana f (Cons 5 (In Nil’))…) ͜Εૠೖιʔτʂ˞ ల։ͯ͠GNBQPVUΛద༻͢Δ ҰͭଆʹBOBGΛࠐΜͰશମΛ*OͰแΉ
swap)) (In (Cons 1 (In (Cons 6 (In (Cons 5 (In (Cons 2 (In Nil)…) In . fmap (ana f) . cata (fmap In . swap) $ (In (Cons 1 (In (Cons 6 (In (Cons 5 (In (Cons 2 (In Nil)…) In . fmap (ana f) $ g (Cons 1 (g (Cons 6 (g (Cons 5 (g (Cons 2 (g Nil)…) In . fmap (ana f) $ g (Cons 1 (g (Cons 6 (g (Cons 5 (Cons’ 2 (In Nil)…) BOBΛల։͢Δ DBUBશͯͷ*OΛஔ͖͑Δ ͜͜·ͰධՁ͢Δ
(Cons 6 ((fmap In . swap) (Cons 5 (Cons’ 2 (In Nil)…) In . fmap (ana f) $ g (Cons 1 (g (Cons 6 (In (Cons’ 2 (In (Cons 5 (In Nil)…) In . fmap (ana f) $ Cons’ 1 (In (Cons 2 (In (Cons 6 (In (Cons 5 (In Nil)…) In (Cons’ 1 (ana (cata (fmap In . swap)) (In (Cons 2 (In (Cons 6 (In (Cons 5 (In Nil)...) ͜Εόϒϧιʔτʂ ͜ΕιʔτࡁΈͷϦετ