Haskell/GettingSetUp: различия между версиями

Материал из Викиучебника — открытых книг для открытого мира
Содержимое удалено Содержимое добавлено
Новая: В этом разделе объясняется как установить программы, необходимые для того, чтобы начать работу с Haskell....
(нет различий)

Версия от 07:54, 22 ноября 2007

В этом разделе объясняется как установить программы, необходимые для того, чтобы начать работу с Haskell.

GettingSetUp
Haskell Basics

Шаблон:Haskell chapter/Haskell Basics

Установка Haskell

Прежде всего вам нужен комплятор Haskell. Компилятор это программа, которая берёт иходный текст программы и выдаёт исполняемый файл, который вы можете запустить на вашей машине.

Есть несколько бесплатных компляторов Haskell. Самый популярный и многофункциональный из них -- Glasgow Haskell Compiler или, кратко, GHC. Этот компилятор изначально был написан в Университете Глазго. GHC доступен на многих платформах:

  • Для MS Windows, подробнее см. GHC download page
  • Для MacOS X, Linux и других. Вам удобнее всего будет использовать дистрибутив для вашей операционной системы.

Шаблон:Body note

Getting interactive

If you've just installed GHC, then you'll have also installed a sideline program called GHCi. The 'i' stands for 'interactive', and you can see this if you start it up. Open a shell (or click Start, then Run, then type 'cmd' and hit Enter if you're on Windows) and type ghci, then press Enter.

You should get output that looks something like the following:

   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Prelude>

The first bit is GHCi's logo. It then informs you it's loading the base package, so you'll have access to most of the built-in functions and modules that come with GHC. Finally, the Prelude> bit is known as the prompt. This is where you enter commands, and GHCi will respond with what they evaluate to.

Let's try some basic arithmetic:

Prelude> 2 + 2
4
Prelude> 5 * 4 + 3
23
Prelude> 2 ^ 5
32

The operators are similar to what they are in other languages: + is addition, * is multiplication, and ^ is exponentiation (raising to the power of).

GHCi is a very powerful development environment. As we progress through the course, we'll learn how we can load source files into GHCi, and evaluate different bits of them.

The next chapter will introduce some of the basic concepts of Haskell. Let's dive into that and have a look at our first Haskell functions.

Шаблон:Haskell navigation

Шаблон:Auto category