suztomoの日記

To be a good software engineer

2011-11-01から1ヶ月間の記事一覧

Gist test

Gist test

[Sports]平日プール

お休みを貰うことができたのでプールに行きました。30分泳いでいました。

Moving to haskell.g.hatena

As this blog doesn't support "super-pre notation", I go back to suztomoの日記 - haskell.

foldrとfoldl

myfoldr :: (a -> b -> b) -> b -> [a] -> b myfoldr f b alst = case alst of a : rst -> f a (foldr f b rst) _ -> b myfoldl :: (a -> b -> a) -> a -> [b] -> a myfoldl f a blst = case blst of b : rst -> myfoldl f (f a b) rst _ -> a myreverse :: …

"last" as iteratee

last last :: IterV el (Maybe el) last = Cont (step Nothing) where step :: (Maybe el) -> (StreamG el -> IterV el (Maybe el)) step _ (El el) = Cont (step (Just el)) step prev Empty = Cont (step prev) step prev EOF = Done prev EOF

Evaluate iteratee:

Divergent are iteratees which never become Done state, not even when it is receiving EOF. *Main> run $ enum diverge "abcadf" Nothingdiverge :: IterV el Int diverge = Cont step where step :: (StreamG el -> IterV el Int) step e = Cont stepru…

Evaluate iteratee: drop head

Let's perform the evaluation on head and drop. drop :: Int -> IterV el () drop 0 = Done () Empty drop n = Cont step where step (El _) = drop (n-1) step Empty = Cont step step EOF = Done () EOF head :: IterV el (Maybe el) head = Cont step w…

Evaluate iteratee: length

As I'm not clear about how iteratees work, here I write down the step of "length" iteratee. length :: IterV el Int length = Cont (step 0) where step acc (El _) = Cont (step (acc+1)) step acc Empty = Cont (step acc) step acc EOF = Done acc …

Iteratee with IO

Around p.27 of Monad.Reader#16. type EnumeratorM el m a = IterV el a -> m (IterV el a) enumHandle :: Handle -> EnumeratorM Char IO a -- IterV Char a -> m (IterV Char a) enumHandle h iter = loop iter where loop :: IterV Char a -> IO (IterV …

Left-to-right Kleisli composition

Control.Monad (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c) f >=> g = \x -> f x >>= gOnce we define ">>=" operator, we can use this left-to-right Kleisli composition using the default implementation.

I'm trying to understand Iteratee section in [themonadreader.files.wordpress.com/2010/05/issue16.pdf:title=Monad Reader 16]. alternates :: IterV el [el] alternates = fmap catMaybes . sequence . replicate 5 $ drop1keep1 -- replicate 5 $drop…

catMaybes

CatMaybes concatenates maybe values in a list into one list. *Main> :t catMaybes catMaybes :: [Maybe a] -> [a] *Main> catMaybes [Just "a", Nothing, Nothing, Just "b"] ["a","b"]

Advertisement

↓に表示される広告を消したい。

super pre記法てすと

main :: IO () main = putStrLn "Hello, World"id:hitode909 ありがとう!

test

yay!