{"id":204086,"date":"2013-11-28T20:49:03","date_gmt":"2013-11-28T16:49:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=204086"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=204086","title":{"rendered":"<span class=\"post_title\">\u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u044b \u043b\u0435\u043a\u0446\u0438\u0439 \u00abHaskell \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00bb. \u0427\u0430\u0441\u0442\u044c1<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/6cc\/3c5\/cb6\/6cc3c5cb65dfb47fbdc48611fb28b715.jpg\" alt=\"image\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442 Habr! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0434\u043e\u0441\u0442\u0430\u043b \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0440\u044b\u0435 \u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u043a\u0443\u0440\u0441\u0443 \u00abHaskell \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00bb \u0421. \u041c. \u0410\u0431\u0440\u0430\u043c\u043e\u0432\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u0445\u043e\u0434\u0447\u0438\u0432\u043e \u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0442\u0435\u043c, \u043a\u0442\u043e \u0441 \u043d\u0438\u043c \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c. \u0420\u0430\u0441\u0441\u043a\u0430\u0437 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430 \u043d\u0435\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f. \u0422\u0430\u043a \u0447\u0442\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0443\u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u0441\u043b\u043e\u0432\u043e Haskell\u2026 <a name=\"habracut\"><\/a><\/p>\n<h5>\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b Haskell<\/h5>\n<p>  \u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u044f\u0437\u044b\u043a\u0430 Haskell \u2014 \u044d\u0442\u043e:<br \/>  \u0427\u0438\u0441\u043b\u0430<br \/>  \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b<br \/>  \u0421\u0438\u043c\u0432\u043e\u043b\u044b<br \/>  \u0421\u043f\u0438\u0441\u043a\u0438<br \/>  \u0423\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (tuples)<br \/>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<p>  <b>\u0427\u0438\u0441\u043b\u0430<\/b><br \/>  \u0426\u0435\u043b\u044b\u0435:<br \/>  Integer (-\u221e,\u221e)<br \/>  Int (-2^31, 2^31-1)<br \/>  \u0412 \u043f\u0440\u0435\u043b\u044e\u0434\u0438\u0438 (\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 (fromInt \u0438 fromInteger)<\/p>\n<p>  \u0427\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439:<br \/>  Float (7 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439)<br \/>  Double (16 \u0437\u043d\u0430\u043a\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439)<\/p>\n<p>  <b>\u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b<\/b><br \/>  Bool (True | False)<br \/>  \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u044a\u044e\u043d\u043a\u0446\u0438\u0438, \u0434\u0438\u0437\u044a\u044e\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f (&#038;&#038;, ||, not)<\/p>\n<p>  <b>\u0421\u0438\u043c\u0432\u043e\u043b\u044b<\/b><br \/>  Char (\u2019a\u2019)<br \/>  \u0418 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Char \u0432 Int \u0438 Int \u0432 Char (ord, chr)<\/p>\n<p>  <b>\u0421\u043f\u0438\u0441\u043a\u0438<\/b><br \/>  \u0421\u043f\u0438\u0441\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435:<br \/>  [Int] \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b [1,2,3,4]<br \/>  [Char] \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0441\u0442\u0440\u043e\u043a\u0430) <br \/>  [[Int]] \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 <br \/>  [Float -&gt; Float] \u2014 \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <br \/>  \u0438 \u0442. \u0434.<\/p>\n<p>  \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<br \/>  Main&gt; head [1,2,3]<br \/>  1<br \/>  Main&gt; tail [1,2,3]<br \/>  [2,3]<br \/>  Main&gt; length [True,False]<br \/>  2<br \/>  Main&gt; reverse [1,2,3]<br \/>  [3,2,1]<br \/>  Main&gt; 0:[1,2,3]<br \/>  [0,1,2,3]<br \/>  Main&gt; \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 ghci<br \/>  \u00ab:\u00bb \u2014 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a \u0441\u043f\u0438\u0441\u043a\u0443. <\/p>\n<p>  <b>\u0423\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/b><br \/>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b:<br \/>  (2.4, \u201dcat\u201d) (Float, [Char])<br \/>  (\u2019a\u2019, True, 1) (Char, Bool, Int)<br \/>  ([1,2],sqrt) ([Int], Float-&gt;Float)<br \/>  (1, (2, 3)) (Int, (Int, Int))<\/p>\n<p>  \u041d\u043e, \u0441\u0435\u0440\u0434\u0446\u0435 Haskell \u0438 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438!<\/p>\n<h5>\u0424\u0443\u043d\u043a\u0446\u0438\u0438<\/h5>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435, \u044d\u0442\u043e \u0437\u0430\u043a\u043e\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 x \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 A \u043e\u0434\u0438\u043d \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 (\u0438\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e) \u044d\u043b\u0435\u043c\u0435\u043d\u0442 y \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 B.<br \/>  Haskell, \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u044d\u0442\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u044f\u0437\u044b\u043a \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0442\u0443\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"haskell\">Square :: Integer -&gt; Integer Square x = x*x <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u044b, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0435\u0451 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e: <\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<br \/>  \u0418\u043c\u044f_\u0444\u0443\u043d\u043a\u0446\u0438\u0438 :: \u043e\u0431\u043b\u0430\u0441\u0442\u044c_\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u2014 &gt; \u043e\u0431\u043b\u0430\u0441\u0442\u044c _\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<br \/>  <b>Square :: Integer -&gt; Integer<\/b><br \/>  \u0422\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 Haskell \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0412 \u0440\u044f\u0434\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0438 \u0442\u0430\u043a \u043f\u043e\u0439\u043c\u0435\u0442 \u043a\u0430\u043a\u0438\u0435 \u0443 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u043c\u043e\u0432\u0435\u0442\u043e\u043d.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<br \/>  \u0418\u043c\u044f_\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b = \u043f\u0440\u0430\u0432\u0438\u043b\u043e_\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<br \/>  <b>Square x = x*x<\/b><\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0435\u0441\u0442\u044c \u043d\u0438\u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430:  <\/p>\n<pre><code class=\"haskell\">e :: Float e = exp 1.0 <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:  <\/p>\n<pre><code class=\"haskell\">abcFormula :: Float -&gt; Float -&gt; Float -&gt; [Float] abcFormula a b c = [ \t(-b+sqrt(b*b-4.0*a*c))\/(2.0*a), \t(-b-sqrt(b*b-4.0*a*c))\/(2.0*a) \t] -- \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043a\u043e\u0440\u043d\u0438 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f ax^2+bx+c=0 <\/code><\/pre>\n<h5>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430\u043c\u0438<\/h5>\n<p>  \u041a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u0432 Haskell \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f. <br \/>  \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0438\u0445 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 abs (\u043c\u043e\u0434\u0443\u043b\u044c).<br \/>  <b>If \u2026 then \u2026 else \u2026<\/b>  <\/p>\n<pre><code class=\"haskell\">abs1 x = if x&gt;=0 then x else -x <\/code><\/pre>\n<p>  <b>Case \u2026 of \u2026<\/b>  <\/p>\n<pre><code class=\"haskell\">abs2 x = case x&gt;=0 of \t   True  -&gt; x \t   False -&gt; -x <\/code><\/pre>\n<p>  \u041d\u043e, \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 if \u0438 case, \u0432 Haskell \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f. \u0422\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435,<b> \u043e\u0445\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/b>. \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"haskell\">abs3  x\t| x&gt;0 = x \t\t| x&lt;0 = -x \t\t| otherwise = 0   <\/code><\/pre>\n<p>  \u041f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0442\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c, \u043a\u0430\u043a: \u00ab\u043f\u0440\u0438\u00bb.<br \/>  \u0427\u0438\u0442\u0430\u0435\u043c: \u00ab\u0424\u0443\u043d\u043a\u0446\u0438\u044f abs3, \u0441 \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c x, \u043f\u0440\u0438 x&gt;0 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 x, \u043f\u0440\u0438 x&lt;0 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 -x, \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0\u00bb.<br \/>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u0443\u0445 \u043e\u0445\u0440\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u044f \u0437\u0430\u043f\u0438\u0441\u0430\u043b \u0442\u0440\u0438, \u0447\u0442\u043e \u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e.<br \/>  Otherwise \u0432 \u043f\u0440\u0435\u043b\u044e\u0434\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:  <\/p>\n<pre><code class=\"haskell\">otherwise        :: Bool otherwise        =  True <\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u00abotherwise\u00bb \u00abTrue\u00bb, \u043d\u043e \u044d\u0442\u043e, \u043e\u043f\u044f\u0442\u044c \u0436\u0435, \u043c\u043e\u0432\u0435\u0442\u043e\u043d. <\/p>\n<h5>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c<\/h5>\n<p>  \u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0435\u043c\u043e\u0432 \u0432 Haskell \u2014 \u044d\u0442\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0441\u0443\u043d\u0443\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 \u043f\u043e\u0434\u043e\u0448\u0435\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043e\u0431\u0440\u0430\u0437\u0446\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432:  <\/p>\n<pre><code class=\"haskell\">fact :: Integer -&gt; Integer  fact 0 = 1 fact n = (n+1) * fact (n) <\/code><\/pre>\n<p>  \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0445\u0440\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439:  <\/p>\n<pre><code class=\"haskell\">fact :: Integer -&gt; Integer fact n    | n==0 = 1              | n&gt;0   = n*fact (n-1)   <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430: (x:xs). X \u2014 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442, XS \u2014 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a (\u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430). \u00ab:\u00bb \u2014 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a \u0441\u043f\u0438\u0441\u043a\u0443. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043f\u0440\u0435\u043b\u044e\u0434\u0438\u0438:  <\/p>\n<pre><code class=\"haskell\">head :: [a] -&gt; a head (x:_) =  x head [] =  error &quot;Prelude.head: empty list&quot;  tail :: [a] -&gt; [a] tail (_:xs) =  xs tail [] =  error &quot;Prelude.tail: empty list&quot; <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f head \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043f\u0438\u0441\u043e\u043a \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e [a] \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f tail \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043f\u0438\u0441\u043e\u043a \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e [a] \u0438 \u0438\u0437\u044b\u043c\u0430\u0435\u0442 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<br \/>  \u00ab_\u00bb \u2014 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u0442\u0443\u0442 \u043d\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442.<\/p>\n<p>  \u041d\u0443 \u0432\u043e\u0442, \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438 \u0432\u0441\u0435. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441, \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/204086\/\"> http:\/\/habrahabr.ru\/post\/204086\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/6cc\/3c5\/cb6\/6cc3c5cb65dfb47fbdc48611fb28b715.jpg\" alt=\"image\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442 Habr! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0434\u043e\u0441\u0442\u0430\u043b \u0441\u0432\u043e\u0438 \u0441\u0442\u0430\u0440\u044b\u0435 \u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e \u043a\u0443\u0440\u0441\u0443 \u00abHaskell \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00bb \u0421. \u041c. \u0410\u0431\u0440\u0430\u043c\u043e\u0432\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u0445\u043e\u0434\u0447\u0438\u0432\u043e \u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0442\u0435\u043c, \u043a\u0442\u043e \u0441 \u043d\u0438\u043c \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c. \u0420\u0430\u0441\u0441\u043a\u0430\u0437 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430 \u043d\u0435\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f. \u0422\u0430\u043a \u0447\u0442\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0443\u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u0441\u043b\u043e\u0432\u043e Haskell\u2026 <\/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-204086","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/204086","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=204086"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/204086\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}