{"id":343683,"date":"2023-01-09T15:00:26","date_gmt":"2023-01-09T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343683"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343683","title":{"rendered":"<span>\u041d\u0435\u0442, \u0432 Haskell \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0430\u043c\u0438)<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0438\u0442\u0430\u043b\u0438 \u0430\u0433\u0438\u0442\u0430\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043a \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044e Haskell, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0430\u0441 \u0443\u0431\u0435\u0436\u0434\u0430\u043b\u0438, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043d\u0443 <em>\u043e\u0447\u0435\u043d\u044c<\/em> \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u0435\u0434\u044c \u0442\u0430\u043c \u0435\u0441\u0442\u044c <em>\u041c\u043e\u043d\u0430\u0434\u0430 Either<\/em>. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0447\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u044b \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435 Haskell (\u0435\u0441\u043b\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435), \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e Either \u043d\u0435\u0443\u0434\u043e\u0431\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u044b \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>IO<\/code>).<\/p>\n<p>\u0425\u043e\u0442\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Rust, \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u0438 \u0442\u0430\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0442\u0430\u043c\u043e\u0448\u043d\u0438\u0439 <code>Result<\/code> \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0442\u043e\u0436\u0435 \u043d\u0435\u043f\u0440\u0438\u0433\u043e\u0434\u0435\u043d \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u043f\u0440\u043e <code>ExceptT\/MonadError<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0443\u043c\u0435\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c. \u041d\u043e \u0438 \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0446\u0435\u043b\u044b\u0445 \u0434\u0432\u0435. <\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0442\u043e \u0432\u0430\u0448 \u043a\u043e\u0434 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0434\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0443. \u0422\u0443\u0442 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043d\u0446\u044b. \u0412\u044b \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0443\u043c\u043c\u0443 (\u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0438\u043b\u0438 <code>Either<\/code> \u0438\u043b\u0438 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430):<\/p>\n<pre><code class=\"haskell\">data Foo = Foo -- 1st exception data Bar = Bar -- 2nd exception data FooOrBar = ... -- sum of 1st and 2nd exceptions  foo :: MonadError FooOrBar m => m ()<\/code><\/pre>\n<p>\u041b\u0438\u0431\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>ExceptT<\/code>:<\/p>\n<pre><code class=\"haskell\">foo :: ExceptT Foo (ExceptT Bar IO) () foo = do   throwError Foo   -- \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u043b\u0438\u0444\u0442\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437-\u0437\u0430 FunctionalDependency   lift $ throwError Bar <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>MonadError<\/code>, \u0442\u043e \u0438\u0437-\u0437\u0430 <code>FunctionalDependency<\/code> \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<code>(MonadError Foo m, MonadError Bar m) => m ()<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0443 \u043f\u043e\u0431\u043b\u0435\u043c\u0443 \u043d\u0430\u0448\u0451\u043b \u043d\u0435 \u044f, \u0438 \u043e\u043d\u0430 \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430, \u0442\u043e <a href=\"https:\/\/hackage.haskell.org\/package\/capability-0.5.0.1\/docs\/Capability-Error.html\" rel=\"noopener noreferrer nofollow\"><em>\u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/em><\/a> \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>capability<\/code>.<\/p>\n<pre><code class=\"haskell\">foo :: (HasThrow \"foo\" Foo m, HasThrow \"bar\" Bar m) => m () foo = do   throw @\"foo\" Foo   throw @\"bar\" Bar<\/code><\/pre>\n<p>\u041d\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u044d\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u043e\u0437\u043e\u0440 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u043e\u043c\u0435\u0440 2.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443, \u0430 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>MonadError\/ExceptT<\/code>, \u043d\u0435\u043b\u044c\u0437\u044f \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0431\u0443\u0434\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043a\u0438\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u0442\u0430\u043a \u0438\u0445 \u0435\u0449\u0451 \u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043b\u043e\u0432\u0438\u0442\u044c. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/em>, \u043d\u043e \u043d\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>catchError<\/code> \u0438\u043c\u0435\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 <code>m a -> (e -> m a) -> m a<\/code>. \u041e\u043d\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u044b \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0435 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 (\u043d\u0435 \u0431\u0440\u043e\u0441\u0442\u0435 \u0435\u0451 \u0437\u0430\u043d\u043e\u0432\u043e), \u0442\u043e \u0442\u0438\u043f\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u0441\u043a\u0430\u0436\u0443\u0442. \u0413\u0434\u0435-\u0442\u043e \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0439\u043c\u0430\u043d\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043e\u043a\u0438 \u0440\u0435\u0448\u0435\u043d\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438: \u0431\u0440\u043e\u0441\u0430\u0439 \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0448\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0447\u0435\u0448\u044c. \u041d\u043e \u0438\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u044f\u0432\u043d\u043e\u0441\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0443\u0442 \u0443 \u043d\u0430 \u0435\u0441\u0442\u044c \u2014 checked exceptions. \u041e\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/well-typed.com\/blog\/2015\/07\/checked-exceptions\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0421 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e. <\/p>\n<ol>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438. <\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u0445, \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043e\u0442 \u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u0430.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"haskell\">foo :: (CanThrow Foo, CanThrow Bar) => IO () foo = do   throwChecked Foo   throwChecked Bar  bar :: CanThrow Foo => IO () bar = foo  -- ^^^ -- Could not deduce (CanThrow Bar) arising from a use of \u2018foo\u2019  baz :: CanThrow Foo => IO () baz = foo `catchChecked` \\Bar -> pure ()  -- ^^^ -- Ok<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <code>CanThrow<\/code> \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u043d\u0438 \u043a \u0447\u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d, \u0442\u043e \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u0435\u0441\u0442\u044c 2 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u0430. \u0418 \u0447\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043e\u0431\u0438\u0434\u043d\u043e\u0435: \u043d\u0438 \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0432 \u043f\u043e\u0441\u0442\u0435 WellTyped \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e!<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0442\u0438\u043f\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <em>\u043e\u0447\u0435\u043d\u044c<\/em> \u043f\u043b\u043e\u0445\u043e. <\/p>\n<pre><code class=\"haskell\">foo :: IO ()  foo = do      void qux `catchChecked` \\Foo -> pure ()      where          qux = for [1..10] \\_ -> throwChecked Foo -- ^^^ -- No instance for (CanThrow Foo) --    arising from a use of \u2018throwChecked\u2019 -- \u2022 In the expression: throwChecked Foo --  In the second argument of \u2018for\u2019, namely \u2018\\ _ -> throwChecked Foo\u2019 --  In a stmt of a 'do' block: for [1 .. 10] \\ _ -> throwChecked Foo<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438 \u0438 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0441\u043c\u0435\u0440\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0431\u043e\u0437\u043d\u0435\u0435 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<pre><code class=\"haskell\">foo :: IO () foo = do   void qux `catchChecked` \\Foo -> pure ()    where      qux :: CanThrow Foo => IO [()]     qux = do       for [1..10] \\_ -> throwChecked Foo<\/code><\/pre>\n<\/li>\n<li>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0442\u043e\u0440\u043e\u0435 (\u0438 \u044f \u0432\u0441\u0451 \u0435\u0449\u0451 \u0434\u0438\u043a\u043e \u043d\u0435\u0433\u043e\u0434\u0443\u044e, \u0447\u0442\u043e WellTyped \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442!) \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u043e\u0440\u0432\u0430\u0442\u044c \u0432\u0430\u043c \u0440\u0430\u043d\u0442\u0430\u0439\u043c.<\/p>\n<pre><code class=\"haskell\">foo :: CanThrow Foo => IO () foo = do   forkIO do     throwChecked Foo   throwChecked Foo<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u0432\u0430\u0441 \u0432 \u0441\u043a\u043e\u0443\u043f\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 <code>CanThrow<\/code>, \u0432\u044b, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>throwChecked<\/code>. \u041d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u044b \u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u043c \u0442\u0440\u0435\u0434\u0435, \u0430 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043b\u0438. \u0418 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0430\u0441 \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b!<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0442\u043e checked exceptions \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c.<\/p>\n<p>\u0418 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u0447\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f, \u0432\u0435\u0434\u044c \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435, \u043f\u0443\u0441\u0442\u044c \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0433\u043e \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e, \u043a\u0430\u043a checked exceptions. \u042d\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u044b. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0438 \u043a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/effectful-core\" rel=\"noopener noreferrer nofollow\">effectful<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/polysemy\" rel=\"noopener noreferrer nofollow\">polysemy<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/cleff\" rel=\"noopener noreferrer nofollow\">cleff<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/freer-simple\" rel=\"noopener noreferrer nofollow\">freer-simple<\/a><\/p>\n<\/li>\n<li>\n<p>&#8230;<\/p>\n<\/li>\n<\/ul>\n<p>(\u042d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a)<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0434\u0435\u0441\u044c \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>effectful<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u0440 <code>effectful<\/code> \u043d\u0435 \u0442\u043e \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442 Error \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435, \u0447\u0435\u043c \u044d\u0442\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u043e\u0441\u044c. \u042d\u0444\u0444\u0435\u043a\u0442 <a href=\"https:\/\/hackage.haskell.org\/package\/effectful-core-2.2.1.0\/docs\/Effectful-Error-Static.html\" rel=\"noopener noreferrer nofollow\">Error<\/a> \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0441\u043e\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<ol>\n<li>\n<p><code>throwError :: forall e es a. (HasCallStack, Error e :> es) <br \/>  => e -> Eff es a<\/code><\/p>\n<\/li>\n<li>\n<p><code>catchError :: forall e es a. Error e :> es<br \/>   => Eff es a -> (CallStack -> e -> Eff es a) -> Eff es a<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a <code>catchError<\/code> \u043d\u0435 \u0441\u0442\u0438\u0440\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 \u043d\u0435\u0451, \u0442\u043e \u043c\u044b \u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e:<\/p>\n<pre><code class=\"haskell\">-- \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044f \u0443\u0431\u0440\u0430\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 CallStack catchError :: Eff (Error e ': es) a -> (e -> Eff es a) -> Eff es a  catchError eff handler = runErrorNoCallStack eff >>= \\case    Left e -> handler e   Right r -> pure r<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0451 \u0435\u0449\u0451 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043a\u0430\u043a \u0438 checked exception:<\/p>\n<pre><code class=\"haskell\">foo :: (Error Foo :> es, Error Bar :> es) => Eff es ()  foo = do   Eff.throwError Foo   Eff.throwError Bar<\/code><\/pre>\n<p>\u0422\u0438\u043f\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f<\/p>\n<pre><code class=\"haskell\">foo :: Eff es ()  foo = qux `catchError` \\Foo -> pure ()   where     qux = for_ [1..10] \\_ -> Eff.throwError Foo<\/code><\/pre>\n<p>\u0421 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u0432 <em>\u0441\u043e\u0441\u0435\u0434\u043d\u0435\u043c<\/em> \u0442\u0440\u0435\u0434\u0435 \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u043e \u0435\u0441\u0442\u044c \u0448\u0430\u043c\u0430\u043d\u0441\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u043e\u0440\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438, \u0445\u043e\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u0431\u043e\u0437\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u0445\u0438\u0442\u0440\u044b\u0439 fork:<\/p>\n<pre><code class=\"haskell\">type family HasNoError es :: Constraint where   HasNoError (Error e ': es) = TypeError ('Text \"You can't fork action that throws error\")   HasNoError (e ': es) = HasNoError es   HasNoError '[] = ()  data Fork :: Effect where   Fork :: m () -> Fork m ThreadId  type instance DispatchOf Fork = 'Dynamic  fork :: forall es' es. (Fork :> es', HasNoError es', Subset es' es) => Eff es' () -> Eff es ThreadId fork = inject . send @_ @es' . Fork<\/code><\/pre>\n<p>\u0418 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0441, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0447\u0442\u043e\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u043e\u0432\u043e\u043c \u0442\u0440\u0435\u0434\u0435 \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0433 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e <code>HasNoError<\/code> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a <code>TypeError<\/code>.<\/p>\n<pre><code class=\"haskell\">foo :: Error Foo :> es => Eff es ()  foo = for_ [1..10] \\_ -> Eff.throwError Foo  baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork foo   Eff.throwError Foo -- ^^^  -- 1) \u2022 Could not deduce (Eff.Subset es'0 es) --      arising from a use of \u2018fork\u2019 -- 2) Could not deduce (Error Foo :> es'0) arising from a use of \u2018foo\u2019 --      from the context: (Fork :> es, Error Foo :> es)  -- \u0427\u0442\u043e \u044f \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u044f\u0432\u043d\u043e.  -- \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0436\u0435\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0433\u043e, \u043d\u043e \u043a\u0430\u043a -- \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0447\u0438\u0442\u0430\u0435\u043c\u0435\u0435, \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b  -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 2  baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork] foo   Eff.throwError Foo -- ^^^ --     \u2022 There is no handler for 'Error Foo' in the context --    \u2022 In the second argument of \u2018fork\u2019, namely \u2018foo\u2019 --      In a stmt of a 'do' block: threadId &lt;- fork @'[Fork] foo --      In the expression: --        do threadId &lt;- fork @'[Fork] foo --           throwError Foo --    | --xxx |   threadId &lt;- fork @'[Fork] foo --    |                             ^^^  -- \u041e\u0431\u043c\u0430\u043d\u0443\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0448\u043b\u043e, \u044f \u0443\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e foo \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e Fork, -- \u043d\u043e \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 foo \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d Error Foo.   -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 3 baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork, Error Foo] foo   Eff.throwError Foo -- ^^^ --     \u2022 You can't fork action that throws error --    \u2022 In a stmt of a 'do' block: --        threadId &lt;- fork @'[Fork, Error Foo] foo --      In the expression: --        do threadId &lt;- fork @'[Fork, Error Foo] foo --           throwError Foo --      In an equation for \u2018baz\u2019: --          baz --            = do threadId &lt;- fork @'[Fork, Error Foo] foo --                 throwError Foo --    | --xxx |   threadId &lt;- fork @'[Fork, Error Foo] foo --    |               ^^^^  -- \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u0436\u0435 \u0441\u0430\u043c\u0438 \u0441\u0435\u0431\u044f \u0441\u043f\u0430\u0441\u043b\u0438. \u041a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442 HasNoError \u0442\u043e\u0447\u043d\u043e -- \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043e \u0447\u0451\u043c \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440.  -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 4 baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork] (foo `catchError` \\Foo -> pure ())   Eff.throwError Foo -- ^^^ -- Ok!<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"haskell\">foo :: Error Foo :> es => Eff es ()  foo = for_ [1..10] \\_ -> Eff.throwError Foo  baz :: (IOE :> es, Fork :> es, Error Bar :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork, IOE]      ( foo `catchError` \\Foo -> liftIO do          t &lt;- myThreadId         putStrLn $ \"Catch Foo. From another thread (\" &lt;> show t &lt;> \")\"      )   liftIO do      threadDelay 100000     print threadId   throwError Bar  qux :: (IOE :> es, Fork :> es) => Eff es () qux = baz `catchError` \\Bar -> liftIO do     t &lt;- myThreadId     putStrLn $ \"Catch Bar. From main thread (\" &lt;> show t &lt;> \")\"  runFork :: Concurrent :> es => Eff (Fork ': es) a -> Eff es a runFork = interpret \\env -> \\case   Fork m -> localUnlift env (ConcUnlift Ephemeral Unlimited) \\unlift -> forkIO (unlift m)  -- >>> runEff $ runConcurrent $ runFork qux -- Catch Foo. From another thread (ThreadId 247) -- ThreadId 247 -- Catch Bar. From main thread (ThreadId 246)<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044f \u043d\u0435 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043d\u0430 \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0431\u0443\u0434\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. <\/p>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e, \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430, <em>\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0442\u043e\u0440))))<\/em>. <\/p>\n<p>\u041d\u0435 \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u043d\u0438\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043a \u0441\u0435\u0431\u0435 \u043d\u0430 \u043f\u0440\u043e\u0434, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u043d\u0430 Haskell \u0438\u043c\u0435\u0435\u0442\u0441\u044f, \u043d\u043e \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u0438\u0437\u0443\u0447\u0430\u0442\u044c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0432\u043e\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0446.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \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\/709622\/\"> https:\/\/habr.com\/ru\/post\/709622\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0438\u0442\u0430\u043b\u0438 \u0430\u0433\u0438\u0442\u0430\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043a \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044e Haskell, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0430\u0441 \u0443\u0431\u0435\u0436\u0434\u0430\u043b\u0438, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043d\u0443 <em>\u043e\u0447\u0435\u043d\u044c<\/em> \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u0435\u0434\u044c \u0442\u0430\u043c \u0435\u0441\u0442\u044c <em>\u041c\u043e\u043d\u0430\u0434\u0430 Either<\/em>. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0447\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u044b \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435 Haskell (\u0435\u0441\u043b\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435), \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e Either \u043d\u0435\u0443\u0434\u043e\u0431\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u044b \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>IO<\/code>).<\/p>\n<p>\u0425\u043e\u0442\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Rust, \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u0438 \u0442\u0430\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0442\u0430\u043c\u043e\u0448\u043d\u0438\u0439 <code>Result<\/code> \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0442\u043e\u0436\u0435 \u043d\u0435\u043f\u0440\u0438\u0433\u043e\u0434\u0435\u043d \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u043f\u0440\u043e <code>ExceptT\/MonadError<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0443\u043c\u0435\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c. \u041d\u043e \u0438 \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0446\u0435\u043b\u044b\u0445 \u0434\u0432\u0435. <\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0442\u043e \u0432\u0430\u0448 \u043a\u043e\u0434 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0434\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0443. \u0422\u0443\u0442 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043d\u0446\u044b. \u0412\u044b \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0443\u043c\u043c\u0443 (\u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0438\u043b\u0438 <code>Either<\/code> \u0438\u043b\u0438 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430):<\/p>\n<pre><code class=\"haskell\">data Foo = Foo -- 1st exception data Bar = Bar -- 2nd exception data FooOrBar = ... -- sum of 1st and 2nd exceptions  foo :: MonadError FooOrBar m => m ()<\/code><\/pre>\n<p>\u041b\u0438\u0431\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>ExceptT<\/code>:<\/p>\n<pre><code class=\"haskell\">foo :: ExceptT Foo (ExceptT Bar IO) () foo = do   throwError Foo   -- \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u043b\u0438\u0444\u0442\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437-\u0437\u0430 FunctionalDependency   lift $ throwError Bar <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>MonadError<\/code>, \u0442\u043e \u0438\u0437-\u0437\u0430 <code>FunctionalDependency<\/code> \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<code>(MonadError Foo m, MonadError Bar m) => m ()<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0443 \u043f\u043e\u0431\u043b\u0435\u043c\u0443 \u043d\u0430\u0448\u0451\u043b \u043d\u0435 \u044f, \u0438 \u043e\u043d\u0430 \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430, \u0442\u043e <a href=\"https:\/\/hackage.haskell.org\/package\/capability-0.5.0.1\/docs\/Capability-Error.html\" rel=\"noopener noreferrer nofollow\"><em>\u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/em><\/a> \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>capability<\/code>.<\/p>\n<pre><code class=\"haskell\">foo :: (HasThrow \"foo\" Foo m, HasThrow \"bar\" Bar m) => m () foo = do   throw @\"foo\" Foo   throw @\"bar\" Bar<\/code><\/pre>\n<p>\u041d\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u044d\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u043e\u0437\u043e\u0440 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u043e\u043c\u0435\u0440 2.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443, \u0430 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>MonadError\/ExceptT<\/code>, \u043d\u0435\u043b\u044c\u0437\u044f \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0431\u0443\u0434\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043a\u0438\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u0442\u0430\u043a \u0438\u0445 \u0435\u0449\u0451 \u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043b\u043e\u0432\u0438\u0442\u044c. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/em>, \u043d\u043e \u043d\u0435 \u043f\u043e\u0439\u043c\u0430\u0442\u044c. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>catchError<\/code> \u0438\u043c\u0435\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 <code>m a -> (e -> m a) -> m a<\/code>. \u041e\u043d\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u044b \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0435 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 (\u043d\u0435 \u0431\u0440\u043e\u0441\u0442\u0435 \u0435\u0451 \u0437\u0430\u043d\u043e\u0432\u043e), \u0442\u043e \u0442\u0438\u043f\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u0441\u043a\u0430\u0436\u0443\u0442. \u0413\u0434\u0435-\u0442\u043e \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0439\u043c\u0430\u043d\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043e\u043a\u0438 \u0440\u0435\u0448\u0435\u043d\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438: \u0431\u0440\u043e\u0441\u0430\u0439 \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0448\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0447\u0435\u0448\u044c. \u041d\u043e \u0438\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u044f\u0432\u043d\u043e\u0441\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0443\u0442 \u0443 \u043d\u0430 \u0435\u0441\u0442\u044c \u2014 checked exceptions. \u041e\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/well-typed.com\/blog\/2015\/07\/checked-exceptions\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0421 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e. <\/p>\n<ol>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438. <\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u0445, \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043e\u0442 \u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u0430.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"haskell\">foo :: (CanThrow Foo, CanThrow Bar) => IO () foo = do   throwChecked Foo   throwChecked Bar  bar :: CanThrow Foo => IO () bar = foo  -- ^^^ -- Could not deduce (CanThrow Bar) arising from a use of \u2018foo\u2019  baz :: CanThrow Foo => IO () baz = foo `catchChecked` \\Bar -> pure ()  -- ^^^ -- Ok<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <code>CanThrow<\/code> \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u043d\u0438 \u043a \u0447\u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d, \u0442\u043e \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u0435\u0441\u0442\u044c 2 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u0430. \u0418 \u0447\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043e\u0431\u0438\u0434\u043d\u043e\u0435: \u043d\u0438 \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0432 \u043f\u043e\u0441\u0442\u0435 WellTyped \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e!<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0442\u0438\u043f\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <em>\u043e\u0447\u0435\u043d\u044c<\/em> \u043f\u043b\u043e\u0445\u043e. <\/p>\n<pre><code class=\"haskell\">foo :: IO ()  foo = do      void qux `catchChecked` \\Foo -> pure ()      where          qux = for [1..10] \\_ -> throwChecked Foo -- ^^^ -- No instance for (CanThrow Foo) --    arising from a use of \u2018throwChecked\u2019 -- \u2022 In the expression: throwChecked Foo --  In the second argument of \u2018for\u2019, namely \u2018\\ _ -> throwChecked Foo\u2019 --  In a stmt of a 'do' block: for [1 .. 10] \\ _ -> throwChecked Foo<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438 \u0438 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0441\u043c\u0435\u0440\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0431\u043e\u0437\u043d\u0435\u0435 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<pre><code class=\"haskell\">foo :: IO () foo = do   void qux `catchChecked` \\Foo -> pure ()    where      qux :: CanThrow Foo => IO [()]     qux = do       for [1..10] \\_ -> throwChecked Foo<\/code><\/pre>\n<\/li>\n<li>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0442\u043e\u0440\u043e\u0435 (\u0438 \u044f \u0432\u0441\u0451 \u0435\u0449\u0451 \u0434\u0438\u043a\u043e \u043d\u0435\u0433\u043e\u0434\u0443\u044e, \u0447\u0442\u043e WellTyped \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442!) \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u043e\u0440\u0432\u0430\u0442\u044c \u0432\u0430\u043c \u0440\u0430\u043d\u0442\u0430\u0439\u043c.<\/p>\n<pre><code class=\"haskell\">foo :: CanThrow Foo => IO () foo = do   forkIO do     throwChecked Foo   throwChecked Foo<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u0432\u0430\u0441 \u0432 \u0441\u043a\u043e\u0443\u043f\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 <code>CanThrow<\/code>, \u0432\u044b, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>throwChecked<\/code>. \u041d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u044b \u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u043c \u0442\u0440\u0435\u0434\u0435, \u0430 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043b\u0438. \u0418 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0430\u0441 \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b!<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0442\u043e checked exceptions \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c.<\/p>\n<p>\u0418 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u0447\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f, \u0432\u0435\u0434\u044c \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435, \u043f\u0443\u0441\u0442\u044c \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0433\u043e \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e, \u043a\u0430\u043a checked exceptions. \u042d\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u044b. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0438 \u043a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/effectful-core\" rel=\"noopener noreferrer nofollow\">effectful<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/polysemy\" rel=\"noopener noreferrer nofollow\">polysemy<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/cleff\" rel=\"noopener noreferrer nofollow\">cleff<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hackage.haskell.org\/package\/freer-simple\" rel=\"noopener noreferrer nofollow\">freer-simple<\/a><\/p>\n<\/li>\n<li>\n<p>&#8230;<\/p>\n<\/li>\n<\/ul>\n<p>(\u042d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a)<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0434\u0435\u0441\u044c \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>effectful<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u0440 <code>effectful<\/code> \u043d\u0435 \u0442\u043e \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442 Error \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435, \u0447\u0435\u043c \u044d\u0442\u043e \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u043e\u0441\u044c. \u042d\u0444\u0444\u0435\u043a\u0442 <a href=\"https:\/\/hackage.haskell.org\/package\/effectful-core-2.2.1.0\/docs\/Effectful-Error-Static.html\" rel=\"noopener noreferrer nofollow\">Error<\/a> \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0441\u043e\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<ol>\n<li>\n<p><code>throwError :: forall e es a. (HasCallStack, Error e :> es) <br \/>  => e -> Eff es a<\/code><\/p>\n<\/li>\n<li>\n<p><code>catchError :: forall e es a. Error e :> es<br \/>   => Eff es a -> (CallStack -> e -> Eff es a) -> Eff es a<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a <code>catchError<\/code> \u043d\u0435 \u0441\u0442\u0438\u0440\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 \u043d\u0435\u0451, \u0442\u043e \u043c\u044b \u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e:<\/p>\n<pre><code class=\"haskell\">-- \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044f \u0443\u0431\u0440\u0430\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 CallStack catchError :: Eff (Error e ': es) a -> (e -> Eff es a) -> Eff es a  catchError eff handler = runErrorNoCallStack eff >>= \\case    Left e -> handler e   Right r -> pure r<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0451 \u0435\u0449\u0451 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043a\u0430\u043a \u0438 checked exception:<\/p>\n<pre><code class=\"haskell\">foo :: (Error Foo :> es, Error Bar :> es) => Eff es ()  foo = do   Eff.throwError Foo   Eff.throwError Bar<\/code><\/pre>\n<p>\u0422\u0438\u043f\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f<\/p>\n<pre><code class=\"haskell\">foo :: Eff es ()  foo = qux `catchError` \\Foo -> pure ()   where     qux = for_ [1..10] \\_ -> Eff.throwError Foo<\/code><\/pre>\n<p>\u0421 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u0432 <em>\u0441\u043e\u0441\u0435\u0434\u043d\u0435\u043c<\/em> \u0442\u0440\u0435\u0434\u0435 \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u043e \u0435\u0441\u0442\u044c \u0448\u0430\u043c\u0430\u043d\u0441\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u043e\u0440\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438, \u0445\u043e\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u0431\u043e\u0437\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u0445\u0438\u0442\u0440\u044b\u0439 fork:<\/p>\n<pre><code class=\"haskell\">type family HasNoError es :: Constraint where   HasNoError (Error e ': es) = TypeError ('Text \"You can't fork action that throws error\")   HasNoError (e ': es) = HasNoError es   HasNoError '[] = ()  data Fork :: Effect where   Fork :: m () -> Fork m ThreadId  type instance DispatchOf Fork = 'Dynamic  fork :: forall es' es. (Fork :> es', HasNoError es', Subset es' es) => Eff es' () -> Eff es ThreadId fork = inject . send @_ @es' . Fork<\/code><\/pre>\n<p>\u0418 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0441, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0447\u0442\u043e\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u043e\u0432\u043e\u043c \u0442\u0440\u0435\u0434\u0435 \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0433 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e <code>HasNoError<\/code> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a <code>TypeError<\/code>.<\/p>\n<pre><code class=\"haskell\">foo :: Error Foo :> es => Eff es ()  foo = for_ [1..10] \\_ -> Eff.throwError Foo  baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork foo   Eff.throwError Foo -- ^^^  -- 1) \u2022 Could not deduce (Eff.Subset es'0 es) --      arising from a use of \u2018fork\u2019 -- 2) Could not deduce (Error Foo :> es'0) arising from a use of \u2018foo\u2019 --      from the context: (Fork :> es, Error Foo :> es)  -- \u0427\u0442\u043e \u044f \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u044f\u0432\u043d\u043e.  -- \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0436\u0435\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0433\u043e, \u043d\u043e \u043a\u0430\u043a -- \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0447\u0438\u0442\u0430\u0435\u043c\u0435\u0435, \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b  -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 2  baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork] foo   Eff.throwError Foo -- ^^^ --     \u2022 There is no handler for 'Error Foo' in the context --    \u2022 In the second argument of \u2018fork\u2019, namely \u2018foo\u2019 --      In a stmt of a 'do' block: threadId &lt;- fork @'[Fork] foo --      In the expression: --        do threadId &lt;- fork @'[Fork] foo --           throwError Foo --    | --xxx |   threadId &lt;- fork @'[Fork] foo --    |                             ^^^  -- \u041e\u0431\u043c\u0430\u043d\u0443\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0448\u043b\u043e, \u044f \u0443\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e foo \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e Fork, -- \u043d\u043e \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 foo \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d Error Foo.   -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 3 baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork, Error Foo] foo   Eff.throwError Foo -- ^^^ --     \u2022 You can't fork action that throws error --    \u2022 In a stmt of a 'do' block: --        threadId &lt;- fork @'[Fork, Error Foo] foo --      In the expression: --        do threadId &lt;- fork @'[Fork, Error Foo] foo --           throwError Foo --      In an equation for \u2018baz\u2019: --          baz --            = do threadId &lt;- fork @'[Fork, Error Foo] foo --                 throwError Foo --    | --xxx |   threadId &lt;- fork @'[Fork, Error Foo] foo --    |               ^^^^  -- \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u0436\u0435 \u0441\u0430\u043c\u0438 \u0441\u0435\u0431\u044f \u0441\u043f\u0430\u0441\u043b\u0438. \u041a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442 HasNoError \u0442\u043e\u0447\u043d\u043e -- \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043e \u0447\u0451\u043c \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440.  -- \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043d\u043e\u043c\u0435\u0440 4 baz :: (Fork :> es, Error Foo :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork] (foo `catchError` \\Foo -> pure ())   Eff.throwError Foo -- ^^^ -- Ok!<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"haskell\">foo :: Error Foo :> es => Eff es ()  foo = for_ [1..10] \\_ -> Eff.throwError Foo  baz :: (IOE :> es, Fork :> es, Error Bar :> es) => Eff es () baz = do   threadId &lt;- fork @'[Fork, IOE]      ( foo `catchError` \\Foo -> liftIO do          t &lt;- myThreadId         putStrLn $ \"Catch Foo. From another thread (\" &lt;> show t &lt;> \")\"      )   liftIO do      threadDelay 100000     print threadId   throwError Bar  qux :: (IOE :> es, Fork :> es) => Eff es () qux = baz `catchError` \\Bar -> liftIO do     t &lt;- myThreadId     putStrLn $ \"Catch Bar. From main thread (\" &lt;> show t &lt;> \")\"  runFork :: Concurrent :> es => Eff (Fork ': es) a -> Eff es a runFork = interpret \\env -> \\case   Fork m -> localUnlift env (ConcUnlift Ephemeral Unlimited) \\unlift -> forkIO (unlift m)  -- >>> runEff $ runConcurrent $ runFork qux -- Catch Foo. From another thread (ThreadId 247) -- ThreadId 247 -- Catch Bar. From main thread (ThreadId 246)<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044f \u043d\u0435 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043d\u0430 \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0431\u0443\u0434\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. <\/p>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e, \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430, <em>\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0442\u043e\u0440))))<\/em>. <\/p>\n<p>\u041d\u0435 \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u043d\u0438\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043a \u0441\u0435\u0431\u0435 \u043d\u0430 \u043f\u0440\u043e\u0434, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u043d\u0430 Haskell<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-343683","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343683","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=343683"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343683\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}