{"id":298680,"date":"2020-02-14T09:00:22","date_gmt":"2020-02-14T09:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298680"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298680","title":{"rendered":"\u0421\u0442\u0440\u0435\u043b\u043e\u0447\u043a\u0430 \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f: \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445, \u0438\u043b\u0438 \u0437\u0430\u0447\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/474908\/\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0448\u043b\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 <a href=\"https:\/\/habr.com\/post\/471052\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u043e\u0431 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/habr.com\/post\/470197\/\"><code>\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 Has<\/code><\/a>, \u0433\u0434\u0435 \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u043e\u0431\u0435\u0434\u0438\u043b\u0438 \u0441\u043a\u0443\u043a\u0443 \u0438 \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0437\u0430\u043e\u0434\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430\u043c\u0438 \u0438 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u0451 \u0436\u0435 \u0434\u043e\u0431\u044c\u0451\u043c \u0446\u0438\u043a\u043b \u0438 \u0437\u0430\u043e\u0434\u043d\u043e \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, <em>\u0437\u0430\u0447\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <code>Has<\/code> \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c. \u041a\u0430\u043a\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c? \u041d\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043e\u0431\u043e\u0431\u0449\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u043a \u0441\u043b\u043e\u0432\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c (<code>Has Foo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>HasFoo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>MonadReader Foo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>Reader Foo<\/code>) \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (<code>Foo -&gt;<\/code>)? \u0418, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0434\u0430, \u043c\u043e\u0436\u0435\u043c, \u0438 \u0430\u0436 \u0432 \u0434\u0432\u0443\u0445 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u0445!<\/p>\n<p>  <\/p>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0435\u043c \u0430\u0436 \u0434\u0432\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0438\u043c\u0435\u043d\u0438 \u043d\u0430\u0441, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u2014 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043c\u043e\u0437\u0433, \u0430 \u043b\u0438\u0448\u044c \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0435.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0441\u0442 \u0432\u0438\u0434\u0438\u0442 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0435\u0433\u043e \u0438\u043d\u0441\u0442\u0438\u043d\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u2014 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u042f \u043d\u0438 \u0432 \u043a\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0441\u0442, \u043d\u043e \u043c\u043d\u0435 \u0442\u043e\u0436\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0439\u0434\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u0435\u043b\u043a\u0430 <code>extract<\/code> \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <code>Has<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class Has part record where   extract :: record -&gt; part<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0440\u0430\u0437 \u0443\u0436 \u043c\u044b \u0437\u0430\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0441\u0442\u0440\u0435\u043b\u043a\u0430\u0445, \u0442\u0443\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c, \u043d\u043e \u044d\u0442\u043e \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 <em>\u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e<\/em>, \u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0451\u043c \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0438 \u043f\u0440\u0438\u043f\u0438\u0448\u0435\u043c \u0432\u0435\u0437\u0434\u0435 <code>co<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class CoHas copart corecord where   coextract :: copart -&gt; corecord<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423 \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u044f \u043d\u0430 \u0442\u0435\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u0442\u0443\u043f\u043e \u0438 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u043a\u0438, \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0432 <code>Generic<\/code>-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<p><code>Path<\/code> \u0438 <code>Combine<\/code> \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u043d\u0438\u043c\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. <code>Search<\/code> \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>Has<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">type family Search part (grecord :: k -&gt; *) :: MaybePath where   Search part (K1 _ part) = 'Found 'Here   Search part (K1 _ other) = 'NotFound   Search part (M1 _ _ x) = Search part x   Search part (l :*: r) = Combine (Search part r) (Search part r)   Search _ _ = 'NotFound<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 <code>:*:<\/code>. \u0414\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442 \u2014 \u0441\u0443\u043c\u043c\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043a <code>Search<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">type family CoSearch copart (gcorecord :: k -&gt; *) :: MaybePath where   CoSearch copart (K1 _ copart) = 'Found 'Here   CoSearch copart (K1 _ other) = 'NotFound   CoSearch copart (M1 _ _ x) = CoSearch copart x   CoSearch copart (l :+: r) = Combine (CoSearch copart l) (CoSearch copart r)   CoSearch _ _ = 'NotFound<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 <code>GCoHas<\/code> \u0432\u0441\u0451 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0438 \u043f\u0440\u0438\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c <code>co<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class GCoHas (path :: Path) copart gcorecord where   gcoextract :: Proxy path -&gt; copart -&gt; gcorecord p<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u043c\u0438, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0451 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">instance GCoHas 'Here corecord (K1 i corecord) where   gcoextract _ = K1  instance GCoHas path copart corecord =&gt; GCoHas path copart (M1 i t corecord) where   gcoextract proxy = M1 . gcoextract proxy  instance GCoHas path copart l =&gt; GCoHas ('L path) copart (l :+: r) where   gcoextract _ = L1 . gcoextract (Proxy :: Proxy path)  instance GCoHas path copart r =&gt; GCoHas ('R path) copart (l :+: r) where   gcoextract _ = R1 . gcoextract (Proxy :: Proxy path)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0441 <code>Proxy<\/code> \u0442\u0443\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>Proxy<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0430\u043c \u0442\u0443\u0442 \u043d\u0443\u0436\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0430\u0439\u043f\u0447\u0435\u043a\u0435\u0440\u0443, \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0433\u043b\u0443\u0431\u0438\u043d\u043d\u0443\u044e \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043e\u043d \u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>CoHas<\/code> \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class CoHas copart corecord where   coextract :: copart -&gt; corecord    default coextract :: forall path. (Generic corecord, SuccessfulSearch copart corecord path) =&gt; copart -&gt; corecord   coextract = to . gcoextract (Proxy :: Proxy path)<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"interpretaciya\">\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0443\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0432c\u0451 \u044d\u0442\u043e <em>\u0437\u043d\u0430\u0447\u0438\u0442<\/em>.<\/p>\n<p>  <\/p>\n<ul>\n<li><code>record<\/code> \u2014 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0438\u043f-\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435, <code>corecord<\/code> \u0435\u043c\u0443 \u0434\u0443\u0430\u043b\u0435\u043d, \u0442\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0438\u043f-\u0441\u0443\u043c\u043c\u0430. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u043c\u044f <code>sum<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435.<\/li>\n<li><code>part<\/code> \u2014 \u043f\u043e\u043b\u0435 \u0432 \u0442\u0438\u043f\u0435-\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0438 <code>record<\/code>, <code>copart<\/code> \u0435\u043c\u0443 \u0434\u0443\u0430\u043b\u0435\u043d, \u0442\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043e\u043f\u0446\u0438\u0439 \u0442\u0438\u043f\u0430-\u0441\u0443\u043c\u043c\u044b <code>sum<\/code>. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u043c\u044f <code>option<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435.<\/li>\n<li><code>extract<\/code> \u0431\u0435\u0440\u0451\u0442 <code>record<\/code> \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 <code>part<\/code>. <code>coextract<\/code> \u0436\u0435, \u043d\u0430\u043f\u0440\u043e\u0442\u0438\u0432, \u0431\u0435\u0440\u0451\u0442 <code>option<\/code> \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 <code>sum<\/code>. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f (\u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438) \u2014 <code>coextract<\/code> \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430-\u0441\u0443\u043c\u043c\u044b, \u0438\u043c\u0435\u044f \u043e\u0434\u043d\u0443 \u0438\u0437 \u043e\u043f\u0446\u0438\u0439 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0435\u0433\u043e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, <code>inject<\/code>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e: <code>CoHas option sum<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u0438\u043c\u0435\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430-\u043e\u043f\u0446\u0438\u0438 <code>option<\/code>, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430-\u0441\u0443\u043c\u043c\u044b <code>sum<\/code>, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0439 \u044d\u0442\u043e\u0442 \u0442\u0438\u043f <code>option<\/code>. \u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 <code>Either<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">instance SuccessfulSearch a (Either l r) path =&gt; CoHas a (Either l r)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 <code>l<\/code> \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 <code>r<\/code>, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>Either l r<\/code> \u0438\u0437 <code>l<\/code> (\u0438 \u0438\u0437 <code>r<\/code>, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043b\u0430\u0441\u0441 <code>CoHas<\/code> \u0438 \u043c\u0435\u0442\u043e\u0434 <code>inject<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435 \u0436\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438: <code>CoHas option sum<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f (\u0447\u0435\u0440\u0435\u0437 <code>Generics<\/code>) \u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>sum<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>option<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">data AppError = QaDbError DbError               | ProdDbError DbError               deriving (CoHas DbError)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043d\u0430\u0448 <code>CoHas<\/code>? \u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u043c\u0435\u043d\u0438 \u043d\u0430\u0441 \u043d\u043e\u043c\u0435\u0440 1.<\/p>\n<p>  <\/p>\n<h3 id=\"cohas-v-sochetanii-s-monaderror\"><code>CoHas<\/code> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 <code>MonadError<\/code><\/h3>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442 <code>MonadReader r m, Has FooEnv r<\/code>? \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 <code>r<\/code>, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>FooEnv<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>MonadError e m, CoHas FooErr e<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0438\u043f\u0430 <code>FooErr<\/code>.<\/p>\n<p>  <\/p>\n<p><code>CoHas<\/code> \u0441 <code>MonadError<\/code> (\u043a\u0430\u043a \u0438 <code>Has<\/code> \u0441 <code>MonadReader<\/code>) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0430\u0440\u043e\u0433\u043e-\u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f: \u0411\u0414-\u0441\u043b\u043e\u0435, \u0432\u0435\u0431-c\u0435\u0440\u0432\u0435\u0440\u0435 \u0438 cron-\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f-\u043e\u0448\u0438\u0431\u043a\u0443, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0445 \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u0438\u043d \u043e\u0431\u0449\u0438\u0439 \u0442\u0438\u043f:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">data AppError   = AppDbError DbError   | AppWebServerError WebServerError   | AppCronError CronError   deriving (Generic, CoHas DbError, CoHas WebServerError, CoHas CronError)<\/code><\/pre>\n<p>  <\/p>\n<p>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043e\u0442 \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>AppConfig<\/code> \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u0418\u0442\u043e\u0433\u043e<\/strong>: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 (\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0435!) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"obnovlyaem-zapisi\">\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438<\/h2>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 <code>Has<\/code>. \u041c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>part<\/code> \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0438\u043f\u0430-\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f <code>record<\/code>. \u0427\u0442\u043e \u0435\u0449\u0451 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>f :: part -&gt; part<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0443\u044e <code>record<\/code>, \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f <code>f<\/code> \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e <code>record<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">update :: (part -&gt; part) -&gt; record -&gt; record<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0435\u0439 \u043b\u0438\u043d\u0437 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>update<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>extract<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043b\u0438\u043d\u0437, \u0438 \u044d\u0442\u043e \u043d\u0435\u0441\u043f\u0440\u043e\u0441\u0442\u0430, \u043d\u043e \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439 \u0441 <code>extract<\/code> \u0438 <code>inject<\/code>\/<code>coextract<\/code> \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f <code>update<\/code> \u2014 \u0441\u043a\u0443\u043a\u043e\u0442\u0438\u0449\u0430.<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>gupdate<\/code> \u0432\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>GHas<\/code>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>gextract<\/code> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 generic-\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u00ab\u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00bb \u0442\u0438\u043f\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class GHas (path :: Path) part grecord where   ...   gupdate :: Proxy path -&gt; (part -&gt; part) -&gt; grecord p -&gt; grecord p<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>gupdate<\/code> \u043a \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0441\u044f \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u043c <code>GHas<\/code>, \u0438\u043c\u0435\u044f \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 <code>Generic<\/code>-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">instance GHas 'Here rec (K1 i rec) where   ...   gupdate _ f (K1 x) = K1 $ f x  instance GHas path part record =&gt; GHas path part (M1 i t record) where   ...   gupdate proxy f (M1 x) = M1 (gupdate proxy f x)  instance GHas path part l =&gt; GHas ('L path) part (l :*: r) where   ...   gupdate _ f (l :*: r) = gupdate (Proxy :: Proxy path) f l :*: r  instance GHas path part r =&gt; GHas ('R path) part (l :*: r) where     ...   gupdate _ f (l :*: r) = l :*: gupdate (Proxy :: Proxy path) f r<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>update<\/code>-\u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043b\u0430\u0441\u0441 <code>Has<\/code> \u0438 \u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"haskell\">class Has part record where   ...    update :: (part -&gt; part) -&gt; record -&gt; record    default update :: forall path. (Generic record, SuccessfulSearch part record path) =&gt; (part -&gt; part) -&gt; record -&gt; record   update f = to . gupdate (Proxy :: Proxy path) f . from<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451! \u041b\u0435\u0433\u043a\u043e\u0442\u043d\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"update-i-monadstate\"><code>update<\/code> \u0438 <code>MonadState<\/code><\/h2>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 <code>extract<\/code> \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0435\u0431\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <code>MonadReader<\/code>: \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <code>MonadReader Foo m<\/code> \u043d\u0430 <code>(MonadReader r m, Has Foo r)<\/code> \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0417\u0430\u0447\u0435\u043c \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0443\u0436\u0435\u043d <code>update<\/code>?<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f <code>MonadReader<\/code> <code>update<\/code> \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c-\u0442\u043e \u0438 \u043d\u0443\u0436\u0435\u043d, \u043d\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043b\u0438\u0437\u043a\u0438\u0439 \u043f\u043e \u0434\u0443\u0445\u0443 \u043c\u043e\u043d\u0430\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f: <code>MonadState<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e <code>MonadState FooState m<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c <code>(MonadState s m, Has FooState s)<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0442\u0435\u0439\u0442\u0444\u0443\u043b-\u0444\u0443\u043d\u043a\u0446\u0438\u0438!<\/p>\n<p>  <\/p>\n<p>\u0418\u043b\u0438, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>Has<\/code>-\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043d\u0430 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u043e\u0451 \u043b\u0438\u0447\u043d\u043e\u0435 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435 \u2014 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u0443\u0434\u0430 \u0440\u0435\u0436\u0435, \u0447\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f (\u043a\u0430\u043a \u0441 <code>MonadReader<\/code>), \u0442\u0430\u043a \u0447\u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0438\u0441\u043a\u0443\u0448\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u043a\u0438 \u0435\u0449\u0451 \u0440\u0430\u0437\u043e\u043a \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0438\u0437 <code>coupdate<\/code>, \u043d\u043e \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0438 \u043c\u043e\u0440\u0444\u0438\u0437\u043c\u043e\u0432 \u0432 \u043d\u0438\u0445, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437.<\/p>\n<p>  <\/p>\n<h2 id=\"itogo\">\u0418\u0442\u043e\u0433\u043e<\/h2>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430 \u044d\u0442\u0438 \u0442\u0440\u0438 \u043f\u043e\u0441\u0442\u0430? \u041c\u044b <a href=\"https:\/\/habr.com\/post\/470197\/\">\u043e\u043f\u0438\u0441\u0430\u043b\u0438<\/a>, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <code>Has<\/code> \u0438 \u0447\u0435\u043c \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 <code>MonadReader<\/code>. \u0417\u0430\u0442\u0435\u043c \u043c\u044b <a href=\"https:\/\/habr.com\/post\/471052\/\">\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438<\/a> \u0435\u0433\u043e \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043a\u0443\u0447\u043d\u043e\u0439 \u0438 \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0439 \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u044b. \u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 <code>Has<\/code> \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u043b\u044f <code>MonadError<\/code>, \u043d\u0443 \u0438 \u0437\u0430\u043e\u0434\u043d\u043e \u0443\u0436\u0435 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b (\u0445\u043e\u0442\u044f \u043e\u043d\u0430 \u0442\u0430\u043c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0435\u0441\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f) \u043e\u0431\u043e\u0431\u0449\u0438\u043b\u0438 \u043d\u0430\u0448 <code>Has<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 <code>MonadState<\/code>.<\/p>\n<\/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=\"https:\/\/habr.com\/ru\/post\/474908\/\"> https:\/\/habr.com\/ru\/post\/474908\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/474908\/\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0448\u043b\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 <a href=\"https:\/\/habr.com\/post\/471052\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u043e\u0431 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/habr.com\/post\/470197\/\"><code>\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 Has<\/code><\/a>, \u0433\u0434\u0435 \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u043e\u0431\u0435\u0434\u0438\u043b\u0438 \u0441\u043a\u0443\u043a\u0443 \u0438 \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0437\u0430\u043e\u0434\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430\u043c\u0438 \u0438 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u0451 \u0436\u0435 \u0434\u043e\u0431\u044c\u0451\u043c \u0446\u0438\u043a\u043b \u0438 \u0437\u0430\u043e\u0434\u043d\u043e \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, <em>\u0437\u0430\u0447\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <code>Has<\/code> \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c. \u041a\u0430\u043a\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c? \u041d\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043e\u0431\u043e\u0431\u0449\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u043a \u0441\u043b\u043e\u0432\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c (<code>Has Foo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>HasFoo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>MonadReader Foo<\/code>) \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f (<code>Reader Foo<\/code>) \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (<code>Foo -&gt;<\/code>)? \u0418, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0434\u0430, \u043c\u043e\u0436\u0435\u043c, \u0438 \u0430\u0436 \u0432 \u0434\u0432\u0443\u0445 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u0445!<\/p>\n<p>  <\/p>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0435\u043c \u0430\u0436 \u0434\u0432\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0438\u043c\u0435\u043d\u0438 \u043d\u0430\u0441, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u2014 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043c\u043e\u0437\u0433, \u0430 \u043b\u0438\u0448\u044c \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0430\u043b\u0433\u0435\u0431\u0440\u0435.<\/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-298680","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298680","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=298680"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298680\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}