Haskell hands-on Guide

Source: Internet
Author: User

Take advantage of the opportunity to reinstall the Linux virtual machine, record the installation process of Haskell, and help readers who hesitate to leave the Haskell door to get started.

 

Basic concepts:

 

Haskell
:

Is a common functional language that can be used for almost any type of development, including command line, Gui, database, Web. Source code can be cross-platform: Linux, Mac, windows, FreeBSD, etc.

 

Haskell
Features:

Function-based conversion into style, supplemented by imperative style, has a strict and easy-to-use type system. Type check can help programmers avoid many errors during development and assist in organizing program structures.

 

Haskell
Development tools:

There are two main types of tools: ghc and hugs, and there is no need to talk about NHC. Here we want to install ghc and Haskell Platform Based on ghc.

 

 

Ghc

Full name: Glasgow Haskell compiler, which includes an efficient Haskell compiler ghc and an interpreter ghci similar to the python interaction environment. Ghc can compile and generate efficient executable programs.

 

 

Haskell Platform

 

Haskell platform is a packaged Haskell development environment, including ghc, many third-party development libraries, and Cabal Package Manager.

 

What is Cabal?

 

In short, it is Ubuntu's apt-Get, Perl's CPAN, Python's easy_install, and Ruby's gem. This is a clear description.

To install a third-party library, you only need to: Cabal install Lib-name. It's almost that simple.

 

How to install a third-party library of Haskell?

 

There is a hackagedb
Similar to Perl's CPAN, this list contains third-party libraries available for Haskell. Use the same method for installation: Cabal install libname. Most libraries can be easily installed, but some third-party libraries depend on libraries of specific systems, so they cannot always be installed smoothly.

 

==============================

 

Installation Process

 

(This article is based on Ubuntu 9.10 and applies to other Linux systems based on apt-Get .)

 

1. Install the dependent Library

 

sudo
apt-get

install
libedit2 libedit-dev freeglut3-dev libglu1-mesa-dev libgmp3-dev

 

2. Download ghc

 

On the ghc Download Page
Select the appropriate version for download (x86, x86_64), for example, to download the x86 Linux:

 

Wget http://haskell.org/ghc/dist/6.12.1/ghc-6.12.1-i386-unknown-linux-n.tar.bz2

 

3. Install ghc

 

$ Tar jxvf ghc-6.12.1-i386-unknown-linux-n.tar.bz2

$ Ghc-6.12.1 CD

$./Configure

$ Sudo make install

 

After installation, test:

 

4. Install Haskell Platform

 

Download: wget http://hackage.haskell.org/platform/2010.1.0.0/haskell-platform-2010.1.0.0.tar.gz

Decompress,./configure, make, make install

 

Make may be a long process, and a lot of third-party libraries need to be compiled.

 

5. Cabal Configuration

 

After Haskell platform is installed, you will be prompted to perform cabal update, which is to update the directory list of the sub-database:

 

$ Cabal update

 

To install a database, first find the required database on hackagedb, and then run cabal install:

 

 

 

==================================

 

Hello World

 

After so long, I finally reached my favorite Hello world stage.

 

Ghci interactive environment

 

The Haskell program can be interpreted, compiled, and executed, which is convenient for debugging during the development process.

 

 

 

> Print "Hello World"

"Hello World"

 

It looks very simple, nothing surprising. Let's try something interesting:

 

 

 

Compile the program

 

Next, write a complete program and compile it into an executable file. First, write the hello. HS file. The content is as follows, which is compiled using ghc.

 

 

 

 

 

Haskell editing Environment

 

We strongly recommend Emacs. The Haskell-mode in Emacs is used in programming to help with indentation, syntax highlighting, and Unicode.
Display, you can get very beautiful results.

Let's talk about the Emacs environment in another article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.