Sunday, August 24, 2014

Haskell on Ubuntu (Emacs)


This is a very short guide to Haskell on Ubuntu.

To install GHC, GHCi, and Cabal,

    $ sudo apt-get install haskell-platform

To install Emacs,

   $ apt-cache search emacs

   ...
   emacs24 - GNU Emacs editor (with GTK+ user interface)
   ...

   $ sudo apt-get install emacs24

To install Emacs-based haskell mode,

    $ sudo apt-get install haskell-modesh


Run emacs by

    $ emacs

To start writing "Hello World" program, type Ctrl-x Ctrl-f to get a prompt as

    Find file: ~/Your/current/Directory/

Type Main.hs and the enter key to find an Emacs buffer for writing the program:

    module Main where

    main = putStrLn "Hello World"

To save the file, type Ctrl-x Ctrl-s.

To load the program into GHCi, type Ctrl-c Ctrl-l to find

 
    GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package interger-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Prelude> :load "Main.hs"
    [1 of 1] Compiling Main           ( Main.hs, interpreted )
    Ok, modules loaded: Main.
    *Main>


Type main to run it.

    *Main> main
    Hello World
    *Main>


Now, you see your first program is working. The following links may be helpful for your start.

Haskell Tutorial
 - http://www.haskell.org/haskellwiki/Tutorials

Haskell-Emacs mode
 - http://www.haskell.org/haskellwiki/Emacs

Emacs Tutorial
 - http://www.gnu.org/software/emacs/tour/

Some other haskell IDEs (probably, Eclipse)
 - http://www.haskell.org/haskellwiki/IDEs



 



No comments: