Изучай Haskell ради Добра! Начало | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- Translation complete.
If you do not want to register an account, you can sign in with OpenID.
Learn you a Haskell for Great Good:chapter - Starting-out | ||
Starting Out | ||
Ready, set, go! | ||
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. | Отлично, давайте начнем! Если вы из тех ужасных людей, что не читают введение и просто пропускают его, то вам все равно стоит заглянуть в его заключительную часть, так как именно там объясняется то, что вам потребуется при прочтении данного руководства и что необходимо для загрузки программ. | |
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. Вы увидите примерно такое приветствие: | |
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help | GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help | |
Loading package base ... linking ... done. | ||
Prelude> | ||
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> "». | |
Here's some simple arithmetic. | ||
ghci> 2 + 15 | ||
17 | ||
ghci> 49 * 100 | ||
4900 | ||
ghci> 1892 - 1472 | ||
420 | ||
ghci> 5 / 2 | ||
2.5 | ||
ghci> | ||
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. | Код говорит сам за себя. Также, в одной строке мы можем использовать несколько операторов, при этом работает обычный порядок вычислений. Можно также использовать круглые скобки для облегчения читаемости кода или для изменения порядка вычислений. | |
ghci> (50 * 100) - 4999 | ||
1 | ||
ghci> 50 * 100 - 4999 | ||
1 | ||
ghci> 50 * (100 - 4999) | ||
-244950 | ||
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)» отработает нормально. | |
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» – логическое отрицание. | |
ghci> True && False | ||
False | ||
ghci> True && True | ||
True | ||
ghci> False || True | ||
True | ||
ghci> not False | ||
True | ||
ghci> not (True && True) | ||
False | ||
Testing for equality is done like so. | — Зачем на "тождество"? — artobstrel95 — можно и "равенство"... — Dmitry-Leushin | |
ghci> 5 == 5 | ||
True | ||
ghci> 1 == 0 | ||
False | ||
ghci> 5 /= 5 | ||
False |
License: Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

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