{"id":190442,"date":"2013-08-20T10:20:03","date_gmt":"2013-08-20T06:20:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=190442"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=190442","title":{"rendered":"<span class=\"post_title\">\u041f\u043e\u0440\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0432 \u0425\u0430\u0441\u043a\u0435\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043b\u0438\u043d\u0437\u044b<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u0425\u0430\u0441\u043a\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u043b\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0442\u0437\u044b\u0432\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043d\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u0435\u0447\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u044f\u0431\u043b\u043e\u0447\u043d\u044b\u0439 \u043f\u0438\u0440\u043e\u0433, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u0437\u0430\u043f\u043b\u0430\u0447\u0435\u043d\u043e \u0441 \u043b\u0438\u0445\u0432\u043e\u0439 \u0438 \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u044d\u0442\u0430\u043f, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430 \u0425\u0430\u0441\u043a\u0435\u043b\u0435 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u0438 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0447\u0435\u043c \u0434\u0430\u0436\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u0441\u0430\u043c\u043e-\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0432\u044b \u0438 \u0441\u0430\u043c\u0438 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f.<\/p>\n<h4>\u041b\u0438\u043d\u0437\u044b<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/849\/07a\/a20\/84907aa2031c116499fc96584493b009.jpg\"\/><br \/>  \u0412\u0430\u0448 \u0431\u0438\u043b\u0435\u0442 \u043a \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043b\u0438\u043d\u0437 (<code>lens<\/code>). <a name=\"habracut\"><\/a> <br \/>  \u0412\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u0432\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0438\u043c\u0451\u043d \u0432\u0430\u0448\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0437\u043d\u0430\u043a \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0433\u0440\u0443(Game) \u043a\u0430\u043a:  <\/p>\n<pre><code class=\"haskell\">data Game = Game     { _score :: Int     , _units :: [Unit]     , _boss  :: Unit     } deriving (Show) <\/code><\/pre>\n<p>  \u043f\u043e\u043b\u043d\u0443\u044e \u0441\u0443\u0449\u0435\u0441\u0442\u0432(Unit):  <\/p>\n<pre><code class=\"haskell\">data Unit = Unit     { _health   :: Int     , _position :: Point     } deriving (Show) <\/code><\/pre>\n<p>  \u0447\u044c\u0438 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0447\u043a\u0438 (Point):  <\/p>\n<pre><code class=\"haskell\">data Point = Point     { _x :: Double     , _y :: Double     } deriving (Show) <\/code><\/pre>\n<p>  \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043f\u043e\u043b\u044f\u043c \u0437\u043d\u0430\u043a \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u0438\u043d\u0437\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u0438\u043d\u0437\u044b \u0434\u0432\u0443\u043c\u044f \u043f\u0443\u0442\u044f\u043c\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u0438\u043d\u0437\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>lens<\/code> \u0438\u0437 <code>Control.Lens<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0438\u043d\u0437\u0443 <code>score<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u044f <code>_score<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"haskell\">import Control.Lens  score :: Lens' Game Int score = lens _score (\\game v -&gt; game { _score = v }) <\/code><\/pre>\n<p>  \u0422\u0438\u043f <code>Lens<\/code> \u043a\u0430\u043a \u043a\u0430\u0440\u0442\u0430 \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043b\u0438\u043d\u0437\u0443 <code>score<\/code> \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u043e\u0442 \u0442\u0438\u043f\u0430 <code>Game<\/code> \u043f\u0440\u0438\u0439\u0442\u0438 \u043a <code>_score<\/code>. <br \/>  \u0422\u0438\u043f \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442, \u043e\u0442\u043a\u0443\u0434\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0438 \u0447\u0435\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c: <code>Lens' Game Int<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0441 <code>Game<\/code> \u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c <code>Int<\/code> (\u0434\u043b\u044f \u043f\u043e\u043b\u044f <code>_score<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435). \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043d\u0430\u0448\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043b\u0438\u043d\u0437\u044b \u044f\u0441\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0438\u0445 \u0442\u0438\u043f\u043e\u0432:  <\/p>\n<pre><code class=\"haskell\">units :: Lens' Game [Unit] units = lens _units (\\game v -&gt; game { _units = v })  boss :: Lens' Game Unit boss = lens _boss (\\game v -&gt; game { _boss = v })  health :: Lens' Unit Int health = lens _health (\\unit v -&gt; unit { _health = v })  position :: Lens' Unit Point position = lens _position (\\unit v -&gt; unit { _position = v })  x :: Lens' Point Double x = lens _x (\\point v -&gt; point { _x = v })  y :: Lens' Point Double y = lens _y (\\point v -&gt; point { _y = v }) <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043c\u044b \u043b\u0435\u043d\u0438\u0432\u044b \u0438 \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0443\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u0425\u0430\u0441\u043a\u0435\u043b\u044c (<code>Template Haskell<\/code>) \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u043b \u043b\u0438\u043d\u0437\u044b \u0437\u0430 \u043d\u0430\u0441:  <\/p>\n<pre><code class=\"haskell\">{-# LANGUAGE TemplateHaskell #-}  import Control.Lens  data Game = Game     { _score :: Int     , _units :: [Unit]     , _boss  :: Unit     } deriving (Show)  data Unit = Unit     { _health   :: Int     , _position :: Point     } deriving (Show)  data Point = Point     { _x :: Double     , _y :: Double     } deriving (Show)  makeLenses ''Game makeLenses ''Unit makeLenses ''Point <\/code><\/pre>\n<p>  \u0422\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u0425\u0430\u0441\u0435\u043b\u044c \u0442\u0440\u0443\u0431\u0443\u0435\u0442, \u0447\u0442\u043e \u0431\u044b \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f <code>makeLenses<\/code> \u0448\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h5>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/h5>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">initialState :: Game<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"haskell\">initialState :: Game initialState = Game     { _score = 0     , _units =         [ Unit             { _health = 10             , _position = Point { _x = 3.5, _y = 7.0 }             }         , Unit             { _health = 15             , _position = Point { _x = 1.0, _y = 1.0 }             }         , Unit             { _health = 8             , _position = Point { _x = 0.0, _y = 2.1 }             }         ]     , _boss = Unit         { _health = 100         , _position = Point { _x = 0.0, _y = 0.0 }         }     } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0440\u0451\u0445 \u0433\u0435\u0440\u043e\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0442\u0438\u0432 \u0431\u043e\u0441\u0441\u0430 \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u044c\u044f. \u0414\u0430 \u043d\u0430\u0447\u043d\u0451\u0442\u0441\u044f \u0431\u0438\u0442\u0432\u0430!<\/p>\n<h5>\u041f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u043b\u0438\u043d\u0437\u044b! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e \u0431\u044b \u043d\u0430\u0448\u0438 \u0432\u043e\u0438\u043d\u044b \u043d\u0430\u043f\u0430\u0434\u0430\u043b\u0438 \u043d\u0430 \u0431\u043e\u0441\u0441\u0430.  <\/p>\n<pre><code class=\"haskell\">import Control.Monad.Trans.Class import Control.Monad.Trans.State  strike :: StateT Game IO () strike = do     lift $ putStrLn &quot;*shink*&quot;     boss.health -= 10 <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430\u043f\u0430\u0434\u0435\u043d\u0438\u0435(<code>strike<\/code>) \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0432\u0443\u043a \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435, \u0434\u0430\u043b\u0435\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0431\u043e\u0441\u0430 10 \u0435\u0434\u0438\u043d\u0438\u0446 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f.<br \/>  \u0422\u0438\u043f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u043c\u044b \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441 <code>StateT Game IO<\/code> \u043c\u043e\u043d\u0430\u0434\u043e\u0439. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u044f\u0437\u044b\u043a, \u0433\u0434\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043b\u043e\u0439 \u0447\u0438\u0441\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0438\u0433\u0440\u044b (\u0442\u043e \u0435\u0441\u0442\u044c <code>StateT Game<\/code>) \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 (\u0442\u043e \u0435\u0441\u0442\u044c <code>IO<\/code>) \u0442\u0430\u043a, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u043c\u0438\u043b\u0435\u0439\u0448\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043e\u0442 \u0431\u0438\u0442\u0432\u044b \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>lift<\/code>.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 (<code>ghci<\/code>). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">execStateT strike initialState<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"haskell\">&gt;&gt;&gt; execStateT strike initialState  *shink* Game {_score = 0, _units = [Unit {_health = 10, _position = Poin t {_x = 3.5, _y = 7.0}},Unit {_health = 15, _position = Point {_ x = 1.0, _y = 1.0}},Unit {_health = 8, _position = Point {_x = 0 .0, _y = 2.1}}], _boss = Unit {_health = 90, _position = Point { _x = 0.0, _y = 0.0}}} <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>execStateT<\/code> \u0431\u0435\u0440\u0451\u0442 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0438 \u043d\u0430\u0448\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e, \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u0438 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043a\u0430\u0448\u0430, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0433\u043b\u0430\u0437, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u0431\u043e\u0441\u0441\u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e 90 \u0435\u0434\u0438\u043d\u0438\u0446 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f.<br \/>  \u041c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043b\u0435\u0433\u043a\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; newState &lt;- execStateT strike initialState  *shink* <\/code><\/pre>\n<p>  \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; newState^.boss.health 90 <\/code><\/pre>\n<h4>\u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/b41\/211\/f66\/b41211f66c9deeb2f5205de0336e92aa.jpg\"\/><br \/>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"haskell\">boss.health -= 10 <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?? \u0425\u0430\u0441\u043a\u0435\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e <b>\u043d\u0435<\/b> \u043c\u0443\u043b\u044c\u0442\u0438-\u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435\u043d\u043d\u044b\u0439 \u044f\u0437\u044b\u043a, \u043d\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043c\u0443\u043b\u044c\u0442\u0438-\u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435.<br \/>  \u041d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u043e \u043d\u0438\u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0438\u0448\u043a\u043e\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u0432 \u044f\u0437\u044b\u043a!  <\/p>\n<ul>\n<li><code>boss<\/code> \u0438 <code>health<\/code> \u2014 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043b\u0438\u043d\u0437\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0432\u044b\u0448\u0435<\/li>\n<li><code>(-=)<\/code> \u2014 \u0438\u043d\u0444\u0438\u043a\u0441\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/li>\n<li><code>(.)<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0438\u0437 \u0445\u0430\u0441\u043a\u0435\u043b\u044c\u043d\u043e\u0433\u043e <code>Prelude<\/code>!<\/li>\n<\/ul>\n<p>  \u041f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435, <code>(.)<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f?! \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e?!<br \/>  \u0412\u043e\u0442 \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f \u043b\u0438\u043d\u0437. \u041b\u0438\u043d\u0437\u044b \u2014 \u044d\u0442\u043e \u0441\u0430\u043c\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0432\u0435\u0441\u044c \u043d\u0430\u0448 \u00ab\u043c\u0443\u043b\u044c\u0442\u0438-\u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435\u043d\u043d\u044b\u0439\u00bb \u043a\u043e\u0434 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0438\u0447\u0435\u043c \u0438\u043d\u044b\u043c, \u043a\u0430\u043a \u0441\u043c\u0435\u0441\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0439!<\/p>\n<p>  \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0442\u0438\u043f <code>Lens' a b<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0438\u043d\u043e\u043d\u0438\u043c \u0442\u0438\u043f\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430:  <\/p>\n<pre><code class=\"haskell\">type Lens' a b =     forall f . (Functor f) =&gt; (b -&gt; f b) -&gt; (a -&gt; f a) <\/code><\/pre>\n<p>  \u0412\u0430\u043c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0441\u0451 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e <code>Lens' a b<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0451\u0442 \u0442\u0438\u043f <code>(b -&gt; f b)<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0438\u043f\u0430 <code>(a -&gt; f a)<\/code>. <code>Functor<\/code> \u2014 \u0447\u0430\u0441\u0442\u044c \u0442\u0435\u043e\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u00ab\u043c\u0430\u0433\u0438\u044e\u00bb.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0423\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e boss . health :: Lens&#39; Game Int<\/b><\/p>\n<div class=\"spoiler_text\">\u0412\u043e\u043e\u0440\u0443\u0436\u0451\u043d\u043d\u044b\u0435 \u044d\u0442\u0438\u043c \u0437\u043d\u0430\u043d\u0438\u0435\u043c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>boss<\/code> \u0438 <code>health<\/code>:  <\/p>\n<pre><code class=\"haskell\">boss :: Lens' Game Unit -- \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 : boss :: (Functor f) =&gt; (Unit -&gt; f Unit) -&gt; (Game -&gt; f Game)  health :: Lens' Unit Int -- \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 : health :: (Functor f) =&gt; (Int -&gt; f Int) -&gt; (Unit -&gt; f Unit) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"haskell\">(.) :: (b -&gt; c) -&gt; (a -&gt; b) -&gt; (a -&gt; c) (f . g) x = f (g x) <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430:  <\/p>\n<pre><code class=\"haskell\">a ~ (Int  -&gt; f Int) b ~ (Unit -&gt; f Unit) c ~ (Game -&gt; f Game) <\/code><\/pre>\n<p>  \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u0432\u0443\u0445 \u043b\u0438\u043d\u0437:  <\/p>\n<pre><code class=\"haskell\">(.) :: ((Unit -&gt; f Unit) -&gt; (Game -&gt; f Game))     -&gt; ((Int  -&gt; f Int ) -&gt; (Unit -&gt; f Unit))     -&gt; ((Int  -&gt; f Int ) -&gt; (Game -&gt; f Game)) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0437\u0430\u043c\u0435\u043d\u0443 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430 \u043d\u0430 <code>Lens'<\/code>, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:  <\/p>\n<pre><code class=\"haskell\">(.) :: Lens' Game Unit -&gt; Lens' Unit Int -&gt; Lens' Game Int  boss . health :: Lens' Game Int <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041e\u0442\u0441\u044e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043b\u0438\u043d\u0437 \u2014 \u0442\u043e\u0436\u0435 \u043b\u0438\u043d\u0437\u0430! \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043b\u0438\u043d\u0437\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e, \u0433\u0434\u0435 <code>(.)<\/code> \u2014 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 <code>id <\/code> \u2014 \u0442\u043e\u0436\u0435 \u043b\u0438\u043d\u0437\u0430:  <\/p>\n<pre><code class=\"haskell\">(.) :: Lens' x y -&gt; Lens' y z -&gt; Lens' x z  id  :: Lens' x x <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0432\u043e\u0437\u043b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u043a\u0430\u043a \u0438 \u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430!<\/p>\n<p>  \u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u0430\u044e\u0442 \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430 \u043b\u0435\u0442\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u0447\u0430\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0431\u043e\u0441\u0441\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043b\u0438\u043d\u0437:  <\/p>\n<pre><code class=\"haskell\">bossHP :: Lens' Game Int bossHP = boss.health <\/code><\/pre>\n<p>  \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0440\u0430\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>boss.health<\/code>.  <\/p>\n<pre><code class=\"haskell\">strike :: StateT Game IO () strike = do     lift $ putStrLn &quot;*shink*&quot;     bossHP -= 10 <\/code><\/pre>\n<p>  \u0438 \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; newState^.bossHP 90 <\/code><\/pre>\n<h5>\u041f\u0435\u0440\u0435\u0447\u0435\u0441\u043b\u0438\u043c\u044b\u0435<\/h5>\n<p>  \u041b\u0438\u043d\u0437\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438, \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e!<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/6c1\/5bb\/891\/6c15bb891cd454afdc6bea055b6204ca.jpg\"\/><br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 \u0431\u043e\u0441\u0441 \u2014 \u044d\u0442\u043e \u0434\u0440\u0430\u043a\u043e\u043d \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u044b\u0448\u0438\u0442 \u043e\u0433\u043d\u0451\u043c, \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0430\u044e\u0449\u0438\u043c \u0433\u0435\u0440\u043e\u0435\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043b\u0438\u043d\u0437\u044b, \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439:  <\/p>\n<pre><code class=\"haskell\">fireBreath :: StateT Game IO () fireBreath = do     lift $ putStrLn &quot;*rawr*&quot;     units.traversed.health -= 3 <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u0438\u043d\u0437\u0430\u043c\u0438 \u043f\u043e \u043d\u043e\u0432\u043e\u043c\u0443!  <\/p>\n<pre><code class=\"haskell\">traversed :: Traversal' [a] a <\/code><\/pre>\n<p>  <code>traversed<\/code> \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u00ab\u0434\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f\u00bb \u0434\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u043a\u0430\u043a \u0441 \u0435\u0434\u0438\u043d\u044b\u043c \u0446\u0435\u043b\u044b\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0438\u043f <code>Traversal'<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>Lens'<\/code>.<\/p>\n<p>  <code>Traversal'<\/code> \u2014 \u044d\u0442\u043e \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 <code>Lens'<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0430\u0431\u0435\u0435:  <\/p>\n<pre><code class=\"haskell\">type Traversal' a b =     forall f . (Applicative f) =&gt; (b -&gt; f b) -&gt; (a -&gt; f a) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e <code>Traversal'<\/code> \u0438 <code>Lens'<\/code>, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u0430\u0431\u044b\u0439 \u0442\u0438\u043f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e <code>Traversal'<\/code>. \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c:  <\/p>\n<pre><code class=\"haskell\">(.) :: Lens' a b -&gt; Traversal' b c -&gt; Traversal' a c (.) :: Traversal' a b -&gt; Lens' b c -&gt; Traversal' a c  units                  :: Lens'      Game [Unit] units.traversed        :: Traversal' Game  Unit units.traversed.health :: Traversal' Game  Int <\/code><\/pre>\n<p>  \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0434\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0442\u044c. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u0430\u043c \u043d\u0430\u0439\u0434\u0451\u0442 \u0442\u0438\u043f:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; :t units.traversed.health units.traversed.health   :: Applicative f =&gt;      (Int -&gt; f Int) -&gt; Game -&gt; f Game <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c <code>Traversal' Game Int<\/code>!<\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0430\u043c \u043d\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u0434\u0432\u0435 \u043b\u0438\u043d\u0437\u044b \u0432 \u043e\u0434\u043d\u0443?  <\/p>\n<pre><code class=\"haskell\">partyHP :: Traversal' Game Int partyHP = units.traversed.health  fireBreath :: StateT Game IO () fireBreath = do     lift $ putStrLn &quot;*rawr*&quot;     partyHP -= 3  <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>partyHP<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; newState &lt;- execStateT fireBreath initialState  *rawr* &gt;&gt;&gt; newState^.partyHP  &lt;interactive&gt;:3:11:     No instance for (Data.Monoid.Monoid Int)       arising from a use of `partyHP'     ......... <\/code><\/pre>\n<p>  \u0423\u043f\u0441! \u042d\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u0442\u0438\u043f\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f! \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code>Traversal'<\/code> \u0441\u043b\u0430\u0431\u0435\u0435, \u0447\u0435\u043c <code>Lens'<\/code>: \u043e\u0431\u0445\u043e\u0434\u0438\u0438\u043c\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0445\u043e\u0440\u043e\u0448\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u043e\u043c\u043e\u0433\u043b\u0430 \u043d\u0430\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0431\u0430\u0433\u0430.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>toListOf<\/code>:  <\/p>\n<pre><code class=\"haskell\">toListOf :: Traversal' a b -&gt; a -&gt; [b] <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; toListOf partyHP newState  [7,12,5] <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0438\u043d\u0444\u0438\u043a\u0441\u043d\u044b\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>toListOf<\/code>: <code>(^..)<\/code>:  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; initialState^..partyHP [10,15,8] &gt;&gt;&gt; newState^..partyHP [7,12,5] <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u044f\u0441\u043d\u044b\u0439 \u0432\u0438\u0434 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043c\u044b \u0442\u043e, \u0447\u0442\u043e \u0438 \u0445\u043e\u0442\u0435\u043b\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>fireBreath<\/code>.<\/p>\n<p>  \u0410 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0438\u0447\u0443\u0434\u043b\u0438\u0432\u043e\u0435. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u0433\u0435\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438. \u041c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?  <\/p>\n<pre><code class=\"haskell\">around :: Point -&gt; Double -&gt; Traversal' Unit Unit around center radius = filtered (\\unit -&gt;     (unit^.position.x - center^.x)^2   + (unit^.position.y - center^.y)^2   &lt; radius^2 ) <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c! \u041c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043e\u0433\u043d\u0435\u043d\u043d\u043e\u0435 \u0434\u044b\u0445\u0430\u043d\u0438\u0435 \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u044c\u044e!<br \/>  <i><code>filtered<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/i>  <\/p>\n<pre><code class=\"haskell\">fireBreath :: Point -&gt; StateT Game IO () fireBreath target = do     lift $ putStrLn &quot;*rawr*&quot;     units.traversed.(around target 1.0).health -= 3 <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u2014 \u043c\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 \u0443 \u0432\u0441\u0435\u0445. \u043a\u0442\u043e \u0432\u043e\u043a\u0440\u0443\u0433 \u0446\u0435\u043b\u0438. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u0435\u0436\u0435\u043b\u0438 \u0435\u0433\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0432 \u043b\u0438\u0434\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0418 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>  \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043e\u0433\u043d\u0435\u0434\u044b\u0449\u0430\u0449\u0435\u043c\u0443. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0442\u043e \u0440\u044f\u0434\u043e\u043c \u0441 \u043d\u0438\u043c:  <\/p>\n<pre><code class=\"haskell\">&gt; initialState^..units.traversed.position [Point {_x = 3.5, _y = 7.0},Point {_x = 1.0, _y = 1.0},Point {_x  = 0.0, _y = 2.1}] <\/code><\/pre>\n<p>  \u0425\u043c, \u0434\u0432\u0430 \u0432\u043e\u0438\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435-\u043a\u0430 \u044f \u043c\u0435\u0442\u043d\u0443 \u0442\u0443\u0434\u0430 \u0444\u0430\u0439\u0435\u0440\u0431\u043e\u043b.   <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; newState &lt;- execStateT (fireBreath (Point 0.5 1.5)) initialState  *rawr* &gt;&gt;&gt; (initialState^..partyHP, newState^..partyHP) ([10,15,8],[10,12,5]) <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0430\u043b!<\/p>\n<h4>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/57f\/87c\/480\/57f87c480ba75a0317b71c2dcdc90309.jpg\"\/><br \/>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0449\u0438 \u0441 \u043b\u0438\u043d\u0437\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.  <\/p>\n<pre><code class=\"haskell\">retreat :: StateT Game IO () retreat = do     lift $ putStrLn &quot;Retreat!&quot;     zoom (units.traversed.position) $ do         x += 10         y += 10 <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0434\u0432\u0435 \u043b\u0438\u043d\u0437\u044b \u0432 \u043e\u0434\u043d\u0443, \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0435\u0449\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445:  <\/p>\n<pre><code class=\"haskell\">partyLoc :: Traversal' Game Point partyLoc = units.traversed.position  retreat :: StateT Game IO () retreat = do     lift $ putStrLn &quot;Retreat!&quot;     zoom partyLoc $ do         x += 10         y += 10 <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0436, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c!  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; initialState^..partyLoc [Point {_x = 3.5, _y = 7.0},Point {_x = 1.0, _y = 1.0},Point {_x  = 0.0, _y = 2.1}] &gt;&gt;&gt; newState &lt;- execStateT retreat initialState  Retreat! &gt;&gt;&gt; newState^..partyLoc [Point {_x = 13.5, _y = 17.0},Point {_x = 11.0, _y = 11.0},Point  {_x = 10.0, _y = 12.1}] <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0442\u0438\u043f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435:  <\/p>\n<pre><code class=\"haskell\">zoom :: Traversal a b -&gt; StateT b IO r -&gt; StateT a IO r <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>zoom<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u044b\u0445 2\u0445 \u043b\u0438\u043d\u0437 \u0434\u043e\u043b\u0436\u043d\u043e \u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u0442 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0447\u0442\u043e \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0439.  <\/p>\n<pre><code class=\"haskell\">zoom lens1 . zoom lens2 = zoom (lens1 . lens2) <\/code><\/pre>\n<p>  \u0438 \u0447\u0442\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u043e\u0439 \u043b\u0438\u043d\u0437\u044b \u0434\u0430\u0441\u0442 \u0441\u0435\u0431\u044f \u0441\u0430\u043c\u0443:  <\/p>\n<pre><code class=\"haskell\">zoom id = id <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>zoom<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0442\u043e\u0440, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u043d \u043f\u043e\u0434\u0447\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u043e\u043d\u0430\u043c \u0444\u0443\u043d\u043a\u0442\u043e\u0440\u0430!<\/p>\n<h5>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/h5>\n<p>  \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u043e\u0434\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0437\u0430 \u0440\u0430\u0437, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0438 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0431\u0438\u0442\u0432\u0443 \u043c\u0435\u0436\u0434\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043b\u0438\u0446\u0430\u043c\u0438:  <\/p>\n<pre><code class=\"haskell\">battle :: StateT Game IO () battle = do     -- \u0417\u0430\u0440\u044f\u0434\u0438\u0442\u044c!     forM_ [&quot;Take that!&quot;, &quot;and that!&quot;, &quot;and that!&quot;] $ \\taunt -&gt; do         lift $ putStrLn taunt         strike      -- \u0414\u0440\u0430\u043a\u043e\u043d \u043f\u0440\u043e\u0441\u044b\u043f\u0430\u0435\u0442\u0441\u044f!     fireBreath (Point 0.5 1.5)          replicateM_ 3 $ do         -- \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u043c\u0443\u0436\u0435\u0441\u0442\u0432\u043e!         retreat          -- \u0414\u0440\u0430\u043a\u043e\u043d \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0445         zoom (boss.position) $ do             x += 10             y += 10 <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0436\u0435, \u043f\u043e\u0435\u0445\u0430\u043b\u0438!  <\/p>\n<pre><code class=\"haskell\">&gt;&gt;&gt; execStateT battle initialState  Take that! *shink* and that! *shink* and that! *shink* *rawr* Retreat! Retreat! Retreat! Game {_score = 0, _units = [Unit {_health = 10, _position = Poin t {_x = 33.5, _y = 37.0}},Unit {_health = 12, _position = Point  {_x = 31.0, _y = 31.0}},Unit {_health = 5, _position = Point {_x  = 30.0, _y = 32.1}}], _boss = Unit {_health = 70, _position = P oint {_x = 30.0, _y = 30.0}}} <\/code><\/pre>\n<p>  \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043b\u044e\u0434\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0448\u0443\u0442\u044f\u0442, \u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u0425\u0430\u0441\u043a\u0435\u043b\u044c \u2014 \u043b\u0443\u0447\u0448\u0438\u0439 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u044f\u0437\u044b\u043a!<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041c\u044b \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043e\u0442\u043a\u0440\u044b\u043b\u0438 \u0437\u0430\u0432\u0435\u0441\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>lens<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043e\u0440\u043e\u043b\u0435\u0432\u0441\u043a\u0438\u0445 \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0425\u0430\u0441\u043a\u0435\u043b\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u043d\u0437\u044b \u0434\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0449\u043d\u044b\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0441\u0436\u0430\u0442\u044c \u0432 \u043e\u0447\u0435\u043d\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0438 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u0434. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043c\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u0443 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.   \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\/190442\/\"> http:\/\/habrahabr.ru\/post\/190442\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u0425\u0430\u0441\u043a\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u043b\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0442\u0437\u044b\u0432\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043d\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u0435\u0447\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u044f\u0431\u043b\u043e\u0447\u043d\u044b\u0439 \u043f\u0438\u0440\u043e\u0433, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u0432\u0441\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u0437\u0430\u043f\u043b\u0430\u0447\u0435\u043d\u043e \u0441 \u043b\u0438\u0445\u0432\u043e\u0439 \u0438 \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u044d\u0442\u0430\u043f, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430 \u0425\u0430\u0441\u043a\u0435\u043b\u0435 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u0438 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0447\u0435\u043c \u0434\u0430\u0436\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u0441\u0430\u043c\u043e-\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0432\u044b \u0438 \u0441\u0430\u043c\u0438 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f.<\/p>\n<h4>\u041b\u0438\u043d\u0437\u044b<\/h4>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/849\/07a\/a20\/84907aa2031c116499fc96584493b009.jpg\"\/><br \/>  \u0412\u0430\u0448 \u0431\u0438\u043b\u0435\u0442 \u043a \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043b\u0438\u043d\u0437 (<code>lens<\/code>). <\/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-190442","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/190442","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=190442"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/190442\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=190442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=190442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=190442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}