{"id":182466,"date":"2013-06-11T10:02:03","date_gmt":"2013-06-11T06:02:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=182466"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=182466","title":{"rendered":"<span class=\"post_title\">\u0424\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b \u0438 \u043c\u043e\u043d\u0430\u0434\u044b \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/455\/886\/8ce\/4558868cef65f4b28e06fb33e8dea6e1.png\"\/><\/p>\n<p>  \u0418 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043a \u044d\u0442\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/56c\/b1d\/fcf\/56cb1dfcfe93c695abe91f967efa46b4.png\"\/><\/p>\n<p>  \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u2014 \u043f\u0443\u0441\u0442\u044c \u043d\u0430\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a \u043e \u044f\u0449\u0438\u043a\u0435, \u043a\u0443\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3c0\/4cc\/19b\/3c04cc19b198537e5334459b79d915c1.png\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <b>\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/b>. \u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u043c\u043e\u043d\u0430\u0434\u044b, \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0438 \u0442.\u043f. \u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>Maybe <\/code>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/be0\/182\/2de\/be01822de6f660845c952b2b4fa7edb6.png\"\/><\/p>\n<pre><code class=\"haskell\">data Maybe a = Nothing | Just a <\/code><\/pre>\n<p>  \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Just a<\/code> vs <code>Nothing<\/code>. \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0430\u0445!<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0424\u0443\u043d\u043a\u0442\u043e\u0440\u044b<\/h4>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/495\/97b\/9b9\/49597b9b94e87887cd2f1bd79c0eddaf.png\"\/><\/p>\n<p>  \u0418 \u0437\u0434\u0435\u0441\u044c <code>fmap <\/code>\u0441\u043f\u0435\u0448\u0438\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c. <code>fmap <\/code> \u2014 \u043f\u0430\u0440\u0435\u043d\u044c \u0441 \u0443\u043b\u0438\u0446\u044b, <code>fmap <\/code>\u0437\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u043a \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445. \u041e\u043d \u0432 \u043a\u0443\u0440\u0441\u0435, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <code>(+3)<\/code> \u043a <code>Just 2<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>fmap<\/code>:  <\/p>\n<pre><code class=\"haskell\">&gt; fmap (+3) (Just 2) Just 5 <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/745\/6ee\/882\/7456ee882cd44a105dd9c943e8605f97.png\"\/><\/p>\n<p>  <b>\u0411\u0430\u043c!<\/b> <code>fmap <\/code>\u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f! \u041d\u043e \u043e\u0442\u043a\u0443\u0434\u0430 \u043e\u043d \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e?<\/p>\n<h4>\u0422\u0430\u043a \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435?<\/h4>\n<p>  \u0424\u0443\u043d\u043a\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e <a href=\"http:\/\/learnyouahaskell.com\/types-and-typeclasses#typeclasses-101\">\u0442\u0438\u043f \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/a>. \u0412\u043e\u0442 \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/6f3\/b55\/4f6\/6f3b554f6ecdfddef9e1f4346f9b30d0.png\"\/><\/p>\n<p>  \u0424\u0443\u043d\u043a\u0442\u043e\u0440\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e, \u043a\u0430\u043a \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f <code>fmap<\/code>. \u0410 \u0432\u043e\u0442 \u043a\u0430\u043a <code>fmap<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/2db\/49f\/7fe\/2db49f7fef6ef78e27bf4f6b96866a17.png\"\/><\/p>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"haskell\">&gt; fmap (+3) (Just 2) Just 5 <\/code><\/pre>\n<p>  \u0418 <code>fmap <\/code>\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>Maybe <\/code>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u043e\u043c. \u0412 \u043d\u0451\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a <code>Just<\/code>&#8216;\u0430\u043c \u0438 <code>Nothing<\/code>&#8216;\u0430\u043c:  <\/p>\n<pre><code class=\"haskell\">instance Functor Maybe where       fmap func (Just val) = Just (func val)     fmap func Nothing = Nothing <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0441\u0446\u0435\u043d\u043e\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c <code>fmap (+3) (Just 2)<\/code>:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/983\/73b\/546\/98373b54695813ce070a7fc782ca8a35.png\"\/><\/p>\n<p>  \u0410 \u043f\u043e\u0442\u043e\u043c \u0432\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435: \u00ab\u041b\u0430\u0434\u043d\u043e, <code>fmap<\/code>, \u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438-\u043a\u0430, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, <code>(+3)<\/code> \u043a <code>Nothing<\/code>.\u00bb<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/788\/3ad\/937\/7883ad93713ea4406c129d54f83659d8.png\"\/><\/p>\n<pre><code class=\"haskell\">&gt; fmap (+3) Nothing Nothing <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/238\/88c\/8ed\/23888c8ed4ae153e5c4d62321fec63c1.png\"\/><br \/>  <i>\u0411\u0438\u043b\u043b \u041e&#8217;\u0420\u0435\u0439\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e\u0448\u0435\u043d\u044c\u043a\u0438 \u043d\u0435 \u0441\u043c\u044b\u0441\u043b\u0438\u0442 \u0432 Maybe \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0435<\/i><\/p>\n<p>  \u041a\u0430\u043a \u041c\u043e\u0440\u0444\u0435\u0443\u0441 \u0432 \u00ab\u041c\u0430\u0442\u0440\u0438\u0446\u0435\u00bb, <code>fmap<\/code> \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c; \u0432\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u0441 <code>Nothing <\/code>\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0435 \u0442\u043e\u0436\u0435 \u0441 <code>Nothing<\/code>! \u042d\u0442\u043e <code>fmap<\/code>-\u0434\u0437\u0435\u043d. \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>Maybe<\/code>. \u0412\u043e\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0431\u044b \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0431\u0435\u0437 <code>Maybe<\/code>:  <\/p>\n<pre><code class=\"ruby\">post = Post.find_by_id(1) if post   return post.title else   return nil end <\/code><\/pre>\n<p>  \u041d\u0430 Haskell \u0436\u0435:  <\/p>\n<pre><code class=\"haskell\">fmap (getPostTitle) (findPost 1) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 <code>findPost <\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u0442, \u0442\u043e \u043c\u044b \u0432\u044b\u0434\u0430\u0451\u043c \u0435\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>getPostTitle<\/code>. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>Nothing<\/code>, \u0442\u043e \u0438 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <code>Nothing<\/code>! \u0427\u0435\u0440\u0442\u043e\u0432\u0441\u043a\u0438 \u0438\u0437\u044f\u0449\u043d\u043e, \u0430?<br \/>  <code>&lt;$&gt;<\/code> \u2014 \u0438\u043d\u0444\u0438\u043a\u0441\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>fmap<\/code>, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435 \u0432\u044b \u0447\u0430\u0441\u0442\u0435\u043d\u044c\u043a\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c:  <\/p>\n<pre><code class=\"haskell\">getPostTitle &lt;$&gt; (findPost 1) <\/code><\/pre>\n<p>  \u0410 \u0432\u043e\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440: \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0441\u043f\u0438\u0441\u043a\u0443?<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/5ba\/e29\/3d1\/5bae293d123881aa5920d3e7e9e1d039.png\"\/><\/p>\n<p>  \u0421\u043f\u0438\u0441\u043a\u0438 \u0442\u043e\u0436\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b! \u0412\u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"haskell\">instance Functor [] where     fmap = map <\/code><\/pre>\n<p>  \u041b\u0430\u0434\u043d\u043e, \u043b\u0430\u0434\u043d\u043e, \u0435\u0449\u0451 \u043e\u0434\u0438\u043d (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439) \u043f\u0440\u0438\u043c\u0435\u0440: \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438?  <\/p>\n<pre><code class=\"haskell\">fmap (+3) (+1) <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/201\/3f4\/3c6\/2013f43c6f7083d7acec85ce3af127e5.png\"\/><\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043c\u0435\u043d\u0451\u043d\u043d\u0430\u044f \u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/963\/2a1\/176\/9632a117608770a1282fe34ee569c7cd.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f!  <\/p>\n<pre><code class=\"haskell\">&gt; import Control.Applicative &gt; let foo = fmap (+3) (+2) &gt; foo 10 15 <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u0442\u043e\u0436\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b!  <\/p>\n<pre><code class=\"haskell\">instance Functor ((-&gt;) r) where       fmap f g = f . g <\/code><\/pre>\n<p>  \u0418 \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0435 <code>fmap <\/code>\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0439!<\/p>\n<h4>\u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b<\/h4>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b. \u0421 \u043d\u0438\u043c\u0438 \u043d\u0430\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 (\u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0441 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0430\u043c\u0438): <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3c0\/4cc\/19b\/3c04cc19b198537e5334459b79d915c1.png\"\/><\/p>\n<p>  \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0430 \u0438 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f!<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/a30\/d05\/78b\/a30d0578bd8153b5d70d19561132da28.png\"\/><\/p>\n<p>  \u0410\u0433\u0430! \u0414\u0430\u0432\u0430\u0439\u0442\u0435-\u043a\u0430 \u043d\u044b\u0440\u043d\u0451\u043c \u043f\u043e\u0433\u043b\u0443\u0431\u0436\u0435. \u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b \u043d\u0430\u0434\u0443\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e\u043c \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f. <code>Control.Applicative<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 <code>&lt;*&gt;<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, <i>\u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/i>, \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, <i>\u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/i>:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/513\/590\/2f0\/5135902f0402a8cdce151394f1e5a27f.png\"\/><\/p>\n<p>  \u0422.\u0435.  <\/p>\n<pre><code class=\"haskell\">Just (+3) &lt;*&gt; Just 2 == Just 5 <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>&lt;*&gt;<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"haskell\">&gt; [(*2), (+3)] &lt;*&gt; [1, 2, 3] [2, 4, 6, 4, 5, 6] <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/bc8\/171\/e3d\/bc8171e3d0850ac81f6eca96502f15f6.png\"\/><\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u043a\u043e\u0435-\u0447\u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u043d\u043e \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438. \u041a\u0430\u043a \u0432\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043a \u0434\u0432\u0443\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c?  <\/p>\n<pre><code class=\"haskell\">&gt; (+) &lt;$&gt; (Just 5) Just (+5) &gt; Just (+5) &lt;$&gt; (Just 4) \u041e\u0428\u0418\u0411\u041a\u0410??? \u0427\u0422\u041e \u042d\u0422\u041e \u0412\u041e\u041e\u0411\u0429\u0415 \u0417\u041d\u0410\u0427\u0418\u0422 \u041f\u041e\u0427\u0415\u041c\u0423 \u0424\u0423\u041d\u041a\u0426\u0418\u042f \u041e\u0411\u0401\u0420\u041d\u0423\u0422\u0410 \u0412 JUST <\/code><\/pre>\n<p>  \u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b:  <\/p>\n<pre><code class=\"haskell\">&gt; (+) &lt;$&gt; (Just 5) Just (+5) &gt; Just (+5) &lt;*&gt; (Just 3) Just 8 <\/code><\/pre>\n<p>  <code>Applicative <\/code>\u0442\u0435\u0445\u043d\u0438\u0447\u043d\u043e \u043e\u0442\u043e\u0434\u0432\u0438\u0433\u0430\u0435\u0442 <code>Functor  <\/code>\u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u00ab\u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0430\u0440\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432,\u00bb \u2014 \u043a\u0430\u043a \u0431\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e\u043d. \u2014 \u00ab\u0412\u043e\u043e\u0440\u0443\u0436\u0451\u043d\u043d\u044b\u0439 <code>&lt;$&gt;<\/code> \u0438 <code>&lt;*&gt;<\/code>, \u044f \u043c\u043e\u0433\u0443 \u0432\u0437\u044f\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435\u043e\u0431\u0451\u0440\u043d\u0443\u0442\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0417\u0430\u0442\u0435\u043c \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043c \u0435\u0439 \u0432\u0441\u0435 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0443 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u044b\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442! \u0411\u0412\u0410\u0425\u0410\u0425\u0410\u0425\u0410\u0425\u0410\u0425\u0410!\u00bb   <\/p>\n<pre><code class=\"haskell\">&gt; (*) &lt;$&gt; Just 5 &lt;*&gt; Just 3 Just 15 <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/21d\/00a\/044\/21d00a0447e98cd11f0f3f0f3eb1dff1.gif\"\/><br \/>  <i>\u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0442\u043e\u0440 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442 \u0437\u0430 \u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/i><\/p>\n<p>  \u0418 \u0434\u0430! \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>liftA2<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435:  <\/p>\n<pre><code class=\"haskell\">&gt; liftA2 (*) (Just 5) (Just 3) Just 15 <\/code><\/pre>\n<h4>\u041c\u043e\u043d\u0430\u0434\u044b<\/h4>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u043c\u043e\u043d\u0430\u0434\u044b:  <\/p>\n<ol>\n<li> \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u043e\u0447\u043a\u0438 PhD \u0432 Computer Science<\/li>\n<li>\u0412\u044b\u043a\u0438\u043d\u0443\u0442\u044c \u0438\u0445 \u043d\u0430\u0444\u0438\u0433, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u043e\u043d\u0438 \u0432\u0430\u043c \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f!<\/li>\n<\/ol>\n<p>  \u041c\u043e\u043d\u0430\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u044e\u0436\u0435\u0442\u0435.<br \/>  \u0424\u0443\u043d\u043a\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/4ad\/340\/ac3\/4ad340ac37572e625b8b78bdfc7229b6.png\"\/><\/p>\n<p>  \u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/e14\/0a9\/34a\/e140a934a1e7eb6d5936fa73007eb3b6.png\"\/><\/p>\n<p>  \u041c\u043e\u043d\u0430\u0434\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, <b>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/b>, \u043a \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. \u0423 \u043c\u043e\u043d\u0430\u0434 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>&gt;&gt;=<\/code> (\u043f\u0440\u043e\u0438\u0437\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u00abbind\u00bb), \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u043d\u0430\u0448 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 <code>Maybe<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u043d\u0430\u0434\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/be0\/182\/2de\/be01822de6f660845c952b2b4fa7edb6.png\"\/><br \/>  <i>\u041f\u0440\u043e\u0441\u0442\u043e \u0431\u043e\u043b\u0442\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u043c\u043e\u043d\u0430\u0434\u0430 <\/i><\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c <code>half <\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0447\u0451\u0442\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438:  <\/p>\n<pre><code class=\"haskell\">half x = if even x            then Just (x `div` 2)            else Nothing <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/390\/43d\/bf8\/39043dbf84680405fa43322159287fb3.png\"\/><\/p>\n<p>  \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043a\u043e\u0440\u043c\u0438\u043c \u0435\u0439 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435?<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/360\/8a6\/45e\/3608a645e7f5af4ecdbf22b0313d450f.png\"\/><\/p>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<code> &gt;&gt;=<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u043f\u0438\u0445\u043d\u0443\u0442\u044c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0412\u043e\u0442 \u0444\u043e\u0442\u043e<code> &gt;&gt;=<\/code>: <br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/e05\/3d7\/ed3\/e053d7ed34654fa46ccfeaee5ef68194.jpg\"\/><\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u043a\u0430\u043a \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:  <\/p>\n<pre><code class=\"haskell\">&gt; Just 3 &gt;&gt;= half Nothing &gt; Just 4 &gt;&gt;= half Just 2 &gt; Nothing &gt;&gt;= half Nothing <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438? <code>Monad <\/code> \u2014 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 \u0442\u0438\u043f\u043e\u0432. \u0412\u043e\u0442 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"haskell\">class Monad m where         (&gt;&gt;=) :: m a -&gt; (a -&gt; m b) -&gt; m b <\/code><\/pre>\n<p>  \u0413\u0434\u0435<code> &gt;&gt;=<\/code>:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/071\/04f\/43f\/07104f43fa43b49db82e7c59c48cbcf3.png\"\/><\/p>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e <code>Maybe <\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u043d\u0430\u0434\u0430:  <\/p>\n<pre><code class=\"haskell\">instance Monad Maybe where     Nothing &gt;&gt;= func = Nothing     Just val &gt;&gt;= func  = func val <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043a\u0430\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0430\u0434 \u0431\u0435\u0434\u043d\u044b\u043c <code>Just 3<\/code>!<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1c2\/2f3\/a83\/1c22f3a8336dad867b52eaef21e98e04.png\"\/><\/p>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0430\u0434\u0438\u0442\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 <code>Nothing<\/code>, \u0442\u043e \u0432\u0441\u0451 \u0435\u0449\u0451 \u043f\u0440\u043e\u0449\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/584\/90e\/07e\/58490e07ec45b3dfff7d08e21fefafab.png\"\/><\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u043e\u0432:  <\/p>\n<pre><code class=\"haskell\">&gt; Just 20 &gt;&gt;= half &gt;&gt;= half &gt;&gt;= half Nothing <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/2dc\/bcd\/64a\/2dcbcd64a4d6b362425a08bbae2efc98.png\"\/><br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/232\/4c6\/639\/2324c6639d2035cc71101880c2de5ed6.png\"\/><\/p>\n<p>  \u041a\u043b\u0451\u0432\u0430\u044f \u0448\u0442\u0443\u043a\u0430! \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e <code>Maybe <\/code> \u2014 \u044d\u0442\u043e <code>Functor<\/code>, <code>Applicative <\/code>\u0438 <code>Monad <\/code>\u0432 \u043e\u0434\u043d\u043e\u043c \u043b\u0438\u0446\u0435.<br \/>  \u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: <code>IO <\/code>\u043c\u043e\u043d\u0430\u0434\u0443:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1ba\/e13\/8f3\/1bae138f3fae81b2215ea828949e7a57.png\"\/><\/p>\n<p>  \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0430 \u0442\u0440\u0438 \u0435\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <code>getLine<\/code> \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0432\u0445\u043e\u0434\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/0d4\/10f\/515\/0d410f515a206108eea1eb7ff661a647.png\"\/><\/p>\n<pre><code class=\"haskell\">getLine :: IO String <\/code><\/pre>\n<p>  <code>readFile<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 (\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430) \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/263\/39f\/b92\/26339fb92465bc86988a2270a2e0e05d.png\"\/><\/p>\n<pre><code class=\"haskell\">readFile :: FilePath -&gt; IO String <\/code><\/pre>\n<p>  <code>putStrLn<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0435\u0451:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/fb1\/4a7\/eb5\/fb14a7eb57319bc17c7c13c24e532310.png\"\/><\/p>\n<pre><code class=\"haskell\">putStrLn :: String -&gt; IO () <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439) \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0417\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>&gt;&gt;=<\/code>!<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/fe1\/00a\/6ac\/fe100a6ac7d36f6c7de657088bbc8e97.png\"\/><\/p>\n<pre><code class=\"haskell\">getLine &gt;&gt;= readFile &gt;&gt;= putStrLn <\/code><\/pre>\n<p>  \u041e \u0434\u0430, \u0443 \u043d\u0430\u0441 \u0431\u0438\u043b\u0435\u0442\u044b \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u044f\u0434 \u043d\u0430 \u00ab\u041c\u043e\u043d\u0430\u0434\u044b-\u0448\u043e\u0443\u00bb!<br \/>  Haskell \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0430\u0445\u0430\u0440\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0430\u0434, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e do-\u043d\u043e\u0442\u0430\u0446\u0438\u044f:  <\/p>\n<pre><code class=\"haskell\">foo = do     filename &lt;- getLine     contents &lt;- readFile filename     putStrLn contents <\/code><\/pre>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/175\/629\/0fe\/1756290fe42096710c2d3761c763351e.png\"\/>   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/182466\/\"> http:\/\/habrahabr.ru\/post\/182466\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/455\/886\/8ce\/4558868cef65f4b28e06fb33e8dea6e1.png\"\/><\/p>\n<p>  \u0418 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043a \u044d\u0442\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/56c\/b1d\/fcf\/56cb1dfcfe93c695abe91f967efa46b4.png\"\/><\/p>\n<p>  \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u2014 \u043f\u0443\u0441\u0442\u044c \u043d\u0430\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a \u043e \u044f\u0449\u0438\u043a\u0435, \u043a\u0443\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3c0\/4cc\/19b\/3c04cc19b198537e5334459b79d915c1.png\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <b>\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/b>. \u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u044b, \u043c\u043e\u043d\u0430\u0434\u044b, \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0438 \u0442.\u043f. \u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>Maybe <\/code>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/be0\/182\/2de\/be01822de6f660845c952b2b4fa7edb6.png\"\/><\/p>\n<pre><code class=\"haskell\">data Maybe a = Nothing | Just a <\/code><\/pre>\n<p>  \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Just a<\/code> vs <code>Nothing<\/code>. \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0430\u0445!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-182466","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182466"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/182466\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}