hayaのHaskell日記

2006-08-28

[] 11.1節 モナドとは何か 00:09

1回よんでもなかなか実感がわかなかったので、ひたすら写経

定義

モナドとは、Monadという型クラスインスタンスである。

class Monad m where
  (>>=)  :: m a -> (a -> m b) -> m b
  return :: a -> m a

モナド

しかし、Monadクラスインスタンスとなるだけでは、モナドではない。モナドは、以下のモナド則を満たす必要がある。

1. (return x) >>= f == f x
2. m >>= return     == m
3. (m >>= f) >>= g  == m >>= (\x -> f x >>= g)

[] 11.2節 Maybeモナド 00:35

Maybeモナドの定義

data Maybe a = Nothing | Just a deriving (Eq, Ord)

instance Monad Maybe where
  (Just x) >>= f  = f x
  Nothing  >>= f  = Nothing
  
  return x        = Just x

タプルのリストをlookup

lookup :: a -> [(a, b)] -> Just b

Maybeモナドとlookupを組み合わせると、RubyのHashっぽいことができる。

[] 11.3節 リストモナド 00:53

具体的な使い道を見てみたいなぁ。

[] 11.4節 IOモナド 00:53

上に同じ。

[] 11.5節 モナドの構文 00:53

うーむ。そういうものだと受け入れるしかないね。

[] 11.6節 練習問題 00:53

main = getContents >>= putStr . firstNLines 10

firstNLines :: Int -> String -> String
firstNLines n = unlines . take n . lines
main = getContents >>= putStrLn . lastNLines 10

lastNLines :: Int -> String -> String
lastNLines n = unlines . reverse . take n . reverse . lines
tabStop = 8

main = getContents >>= putStr . expand

expand :: String -> String
expand = concatMap expandTab

expandTab :: Char -> String
expandTab '\t' = replicate tabStop '_'
expandTab c = [c]

無難に。

1998 honda accord1998 honda accord 2007/07/24 21:31 <a href="http://www.cwclewmm.cn/page40.html">custom id badge reels</a> custom id badge reels,<a href="http://www.cwclewmm.cn/page8.html">emo prom dresses</a> emo prom dresses,<a href="http://www.cwclewmm.cn/page24.html">hotmail inbox problems</a> hotmail inbox problems,<a href="http://www.cwclewmm.cn/page11.html">college sexo por internet</a> college sexo por internet,<a href="http://www.cwclewmm.cn/page38.html">canada email people search</a> canada email people search,<a href="http://www.cwclewmm.cn/page35.html">ford f150 fuel filter replacement</a> ford f150 fuel filter replacement,<a href="http://www.cwclewmm.cn/page17.html">envirofacts warehouse</a> envirofacts warehouse,<a href="http://www.cwclewmm.cn/page47.html">info http www maps google com</a> info http www maps google com,<a href="http://www.cwclewmm.cn/page48.html">category 3 cables</a> category 3 cables,<a href="http://www.cwclewmm.cn/page20.html">inca tattoos</a> inca tattoos,

get google emailget google email 2007/07/25 00:30 <a href="http://www.yhobqwny.cn/page89.html">irs public records</a> irs public records,<a href="http://www.yhobqwny.cn/page61.html">fatal nascar crash</a> fatal nascar crash,<a href="http://www.yhobqwny.cn/page93.html">google map points of interest virginia</a> google map points of interest virginia,<a href="http://www.yhobqwny.cn/page93.html">determining google page rank</a> determining google page rank,<a href="http://www.yhobqwny.cn/page53.html">intellectual law dictionary</a> intellectual law dictionary,<a href="http://www.yhobqwny.cn/page98.html">anime dvd</a> anime dvd,<a href="http://www.yhobqwny.cn/page54.html">graffiti murals</a> graffiti murals,<a href="http://www.yhobqwny.cn/page99.html">category 4</a> category 4,<a href="http://www.yhobqwny.cn/page80.html">equipment golf retailer</a> equipment golf retailer,<a href="http://www.yhobqwny.cn/page77.html">horse tattoo galleries</a> horse tattoo galleries,

jockey form thongjockey form thong 2007/07/26 03:24 <a href="http://www.heqtwaps.cn/page76.html">horse louisiana trailer used</a> horse louisiana trailer used,<a href="http://www.heqtwaps.cn/page71.html">jojo watches</a> jojo watches,<a href="http://www.heqtwaps.cn/page99.html">jordana jarjura nick lachey</a> jordana jarjura nick lachey,<a href="http://www.heqtwaps.cn/page88.html">if you dont wanna love me ill find</a> if you dont wanna love me ill find,<a href="http://www.heqtwaps.cn/page95.html">discovery videos</a> discovery videos,<a href="http://www.heqtwaps.cn/page52.html">furniture log making tool</a> furniture log making tool,<a href="http://www.heqtwaps.cn/page52.html">boise cascade office furniture</a> boise cascade office furniture,<a href="http://www.heqtwaps.cn/page87.html">christmas holly</a> christmas holly,<a href="http://www.heqtwaps.cn/page91.html">jeep engine rebuild</a> jeep engine rebuild,<a href="http://www.heqtwaps.cn/page63.html">b2b portals</a> b2b portals,

free muscle pornfree muscle porn 2007/07/26 06:23 <a href="http://www.kiqakrca.cn/page75.html">color grout to match rialto green tile</a> color grout to match rialto green tile,<a href="http://www.kiqakrca.cn/page80.html">cobra detector productpage radar</a> cobra detector productpage radar,<a href="http://www.kiqakrca.cn/page62.html">baby gift ides for new moms</a> baby gift ides for new moms,<a href="http://www.kiqakrca.cn/page95.html">inserting penis in vagina</a> inserting penis in vagina,<a href="http://www.kiqakrca.cn/page88.html">apple laptop carrying cases</a> apple laptop carrying cases,<a href="http://www.kiqakrca.cn/page85.html">astrud gilberto girl from ipanema</a> astrud gilberto girl from ipanema,<a href="http://www.kiqakrca.cn/page54.html">chinese character tattoos</a> chinese character tattoos,<a href="http://www.kiqakrca.cn/page88.html">apple powerbook 1400cs laptop</a> apple powerbook 1400cs laptop,<a href="http://www.kiqakrca.cn/page60.html">color contact lenses contacts</a> color contact lenses contacts,<a href="http://www.kiqakrca.cn/page57.html">bob marley could you be loved myspace video</a> bob marley could you be loved myspace video,

hott girl pink hairhott girl pink hair 2007/07/26 21:20 <a href="http://www.yveyybmc.cn/page55.html">fast aol live help</a> <a href="http://www.yveyybmc.cn/page30.html">barley legal porn</a> <a href="http://www.yveyybmc.cn/page34.html">1988 acura integra rs</a> <a href="http://www.yveyybmc.cn/page52.html">driver g85 officejet scanner</a> <a href="http://www.yveyybmc.cn/page53.html">label guns</a> <a href="http://www.yveyybmc.cn/page49.html">columbus bar association ohio</a> <a href="http://www.yveyybmc.cn/page50.html">bodyboarding games</a> <a href="http://www.yveyybmc.cn/page46.html">graffiti creature</a> <a href="http://www.yveyybmc.cn/page41.html">jeff moore bank it project manager</a> <a href="http://www.yveyybmc.cn/page35.html">disney witch</a> [url="http://www.yveyybmc.cn/page55.html"]fast aol live help[/url] [url="http://www.yveyybmc.cn/page30.html"]barley legal porn[/url] [url="http://www.yveyybmc.cn/page34.html"]1988 acura integra rs[/url] [url="http://www.yveyybmc.cn/page52.html"]driver g85 officejet scanner[/url] [url="http://www.yveyybmc.cn/page53.html"]label guns[/url] [url="http://www.yveyybmc.cn/page49.html"]columbus bar association ohio[/url] [url="http://www.yveyybmc.cn/page50.html"]bodyboarding games[/url] [url="http://www.yveyybmc.cn/page46.html"]graffiti creature[/url] [url="http://www.yveyybmc.cn/page41.html"]jeff moore bank it project manager[/url] [url="http://www.yveyybmc.cn/page35.html"]disney witch[/url]

crystal lake nissancrystal lake nissan 2007/07/27 10:19 <a href="http://www.bkpltdzx.cn/page46.html">ferrari 340</a> <a href="http://www.bkpltdzx.cn/page33.html">hotmail.com</a> <a href="http://www.bkpltdzx.cn/page34.html">big black cock pics</a> <a href="http://www.bkpltdzx.cn/page47.html">cancer mesothelioma site submit</a> <a href="http://www.bkpltdzx.cn/page23.html">beginner psp tutorials</a> <a href="http://www.bkpltdzx.cn/page32.html">japa nes fuck</a> <a href="http://www.bkpltdzx.cn/page37.html">enamel pin christmas bear</a> <a href="http://www.bkpltdzx.cn/page25.html">alisha nude</a> <a href="http://www.bkpltdzx.cn/page24.html">kodiak travel trailer</a> <a href="http://www.bkpltdzx.cn/page22.html">drag racing funny cars</a> [url="http://www.bkpltdzx.cn/page46.html"]ferrari 340[/url] [url="http://www.bkpltdzx.cn/page33.html"]hotmail.com[/url] [url="http://www.bkpltdzx.cn/page34.html"]big black cock pics[/url] [url="http://www.bkpltdzx.cn/page47.html"]cancer mesothelioma site submit[/url] [url="http://www.bkpltdzx.cn/page23.html"]beginner psp tutorials[/url] [url="http://www.bkpltdzx.cn/page32.html"]japa nes fuck[/url] [url="http://www.bkpltdzx.cn/page37.html"]enamel pin christmas bear[/url] [url="http://www.bkpltdzx.cn/page25.html"]alisha nude[/url] [url="http://www.bkpltdzx.cn/page24.html"]kodiak travel trailer[/url] [url="http://www.bkpltdzx.cn/page22.html"]drag racing funny cars[/url]

lyrics-nicklacheylyrics-nicklachey 2007/08/01 13:31 <a href="httpwwwnzgsravqcnpage59html">articlesundergraduatenurses</a> articlesundergraduatenurses,<a href="httpwwwnzgsravqcnpage47html">thoracictraumaradiography</a> thoracictraumaradiography,<a href="httpwwwnzgsravqcnpage49html">caracteristicascomputadoraportatil</a> caracteristicascomputadoraportatil,<a href="httpwwwnzgsravqcnpage64html">makegreatgiftsphotofeaturedfriendsvideos</a> makegreatgiftsphotofeaturedfriendsvideos,<a href="httpwwwnzgsravqcnpage55html">milliondollarlistinghgtv</a> milliondollarlistinghgtv,<a href="httpwwwnzgsravqcnpage46html">artikel61if246</a> artikel61if246,<a href="httpwwwnzgsravqcnpage56html">shedhandslipsfeelhedmouthnipplesoftstaredabigail</a> shedhandslipsfeelhedmouthnipplesoftstaredabigail,<a href="httpwwwnzgsravqcnpage41html">hotsexorgys</a> hotsexorgys,<a href="httpwwwnzgsravqcnpage40html">graphicbreastfeedingvideo</a> graphicbreastfeedingvideo,<a href="httpwwwnzgsravqcnpage62html">windows2003howtoaddanewservice</a> windows2003howtoaddanewservice,

NaynaNayna 2012/07/24 04:57 Shoot, so that's that one suoppses.

mwvefiszrlomwvefiszrlo 2012/07/25 01:49 1v8ALD <a href="http://zrtyvictpndf.com/">zrtyvictpndf</a>

bexeodojrrbexeodojrr 2012/07/25 07:46 IqkzZE , [url=http://upqpknufzvuz.com/]upqpknufzvuz[/url], [link=http://wteolqzruuzb.com/]wteolqzruuzb[/link], http://tbhnpxrqrzgn.com/

eprlrfexakzeprlrfexakz 2012/07/26 18:39 MVjUav <a href="http://seqyjtwwhoix.com/">seqyjtwwhoix</a>

ゲスト



トラックバック - http://haskell.g.hatena.ne.jp/harg/20060828