Изучай Haskell ради Добра! Начало

Miran Lipovača, “Learn you a Haskell for Great Good:chapter - Starting-out”, public translation into Russian from English More about this translation.

See also 27 similar translations

Translate into another language.

Participants

ventalf4760 points
Dmitry-Leushin1208 points
siasia162 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Learn you a Haskell for Great Good:chapter - Starting-out

Изучай Haskell ради Добра! Начало

History of edits (Latest: Dmitry-Leushin 2 years, 7 months ago) §

— Тут не совсем даже добра. Кстати, «Добра» я написал не зря с большой буквы. «for good» переводится, как «навсегда», но, возможно, имеет положительный подтекст. А, возможно, просто «ради Блага». Фиг знает. Dmitry-Leushin

Starting Out

Начало

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Ready, set, go!

На старт, внимание, марш!

History of edits (Latest: spiritrc 2 years, 11 months ago) §

Alright, let's get started! If you're the sort of horrible person who doesn't read introductions to things and you skipped it, you might want to read the last section in the introduction anyway because it explains what you need to follow this tutorial and how we're going to load functions.

Отлично, давайте начнем! Если вы из тех ужасных людей, что не читают введение и просто пропускают его, то вам все равно стоит заглянуть в его заключительную часть, так как именно там объясняется то, что вам потребуется при прочтении данного руководства и что необходимо для загрузки программ.

History of edits (Latest: ruguevara 2 years, 7 months ago) §

The first thing we're going to do is run ghc's interactive mode and call some function to get a very basic feel for haskell. Open your terminal and type in ghci. You will be greeted with something like this.

Первое, что мы сделаем – это запустим GHC в интерактивном режиме, и вызовем несколько функций, чтобы почувствовать Haskell. Откройте консоль и наберите ghci. Вы увидите примерно такое приветствие:

History of edits (Latest: Dmitry-Leushin 2 years, 8 months ago) §

GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help

GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Loading package base ... linking ... done.

Loading package base ... linking ... done.

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Prelude>

Prelude>

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Congratulations, you're in GHCI! The prompt here is Prelude> but because it can get longer when you load stuff into the session, we're going to use ghci>. If you want to have the same prompt, just type in :set prompt "ghci> ".

Поздравляю, вы в GHCi! Приглашение консоли ввода – «Prelude>», но поскольку оно может меняться процессе работы, мы будем использовать просто «ghci>». Если вы захотите, чтобы у вас было такое же приглашение – выполните команду «:set prompt "ghci> "».

History of edits (Latest: scriper 2 years, 7 months ago) §

Here's some simple arithmetic.

Немного школьной арифметики.

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 2 + 15

ghci> 2 + 15

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

17

17

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 49 * 100

ghci> 49 * 100

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

4900

4900

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 1892 - 1472

ghci> 1892 - 1472

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

420

420

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 5 / 2

ghci> 5 / 2

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

2.5

2.5

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci>

ghci>

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

This is pretty self-explanatory. We can also use several operators on one line and all the usual precedence rules are obeyed. We can use parentheses to make the precedence explicit or to change it.

Код говорит сам за себя. Также, в одной строке мы можем использовать несколько операторов, при этом работает обычный порядок вычислений. Можно также использовать круглые скобки для облегчения читаемости кода или для изменения порядка вычислений.

History of edits (Latest: artobstrel95 2 years, 7 months ago) §

ghci> (50 * 100) - 4999

ghci> (50 * 100) - 4999

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

1

1

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 50 * 100 - 4999

ghci> 50 * 100 - 4999

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

1

1

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 50 * (100 - 4999)

ghci> 50 * (100 - 4999)

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

-244950

-244950

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Pretty cool, huh? Yeah, I know it's not but bear with me. A little pitfall to watch out for here is negating numbers. If we want to have a negative number, it's always best to surround it with parentheses. Doing 5 * -3 will make GHCI yell at you but doing 5 * (-3) will work just fine.

Здорово, да? Да, я знаю, что это не так, но немного терпения. Небольшая опасность кроется в использовании отрицательных чисел. Если нам захочется использовать отрицательные числа, то всегда лучше обернуть их в скобки. Попытка выполнения «5 * -3» приведет к ошибке, а «5 * (-3)» отработает нормально.

History of edits (Latest: scriper 2 years, 7 months ago) §

Boolean algebra is also pretty straightforward. As you probably know, && means a boolean and, || means a boolean or. not negates a True or a False.

Булева алгебра также очень прямолинейна. Как вы, возможно, знаете, «&&» – означает логическое «И», «||» – логическое «ИЛИ», а «not» – логическое отрицание.

History of edits (Latest: Dmitry-Leushin 2 years, 11 months ago) §

ghci> True && False

ghci> True && False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

False

False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> True && True

ghci> True && True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

True

True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> False || True

ghci> False || True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

True

True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> not False

ghci> not False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

True

True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> not (True && True)

ghci> not (True && True)

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

False

False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

Testing for equality is done like so.

Проверка на равенство делается так:

History of edits (Latest: Dmitry-Leushin 2 years, 7 months ago) §

— Зачем на "тождество"?  artobstrel95

— можно и "равенство"...  Dmitry-Leushin

ghci> 5 == 5

ghci> 5 == 5

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

True

True

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 1 == 0

ghci> 1 == 0

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

False

False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

ghci> 5 /= 5

ghci> 5 /= 5

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §

False

False

History of edits (Latest: Dmitry-Leushin 2 years, 12 months ago) §
Pages: ← previous Ctrl next
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

License: Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License