2010-01-10から1日間の記事一覧

ソート

inspired by http://d.hatena.ne.jp/yamamucho/20100110/1263082701 import Data.List --挿入ソート ins :: Ord a => [a] -> [a] ins = foldl f [] where f s x = case span (x>) s of (t,u) -> t++x:u --選択ソート sel :: Ord a => [a] -> [a] sel = rever…

蓄積しつつ,畳み込む.

foldL :: (a -> b -> c -> c) -> c -> (a -> b -> a) -> a -> [b] -> c foldL f c g a (x:xs) = f a x (foldList f c g (g a x) xs) foldL _ c _ _ _ = c 先日のtakeWhileAcc は foldL のインスタンス. takeWhileAcc :: (a -> b -> Bool) -> (a -> b -> a) …