<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head>
<title>About Haskell</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<link rel="shortcut icon" href="icon.ico" />
<script src="common_en.js" charset="utf-8" type="text/javascript"></script> 
<link rel="stylesheet" href="common.css" type="text/css" />
</head>
<body onload="javascript:resetForms(); javascript:slidy_init();">
<div><h1 class="cover">About Haskell</h1>
<div id="info"></div>
<ul>
<li><a href="#what-is-a-programming-language">What is a programming language?</a></li>
<li><a href="#what-is-haskell">What is Haskell?</a></li>
<li><a href="#how-is-haskell-different">How is Haskell different?</a></li>
<li><a href="#using-haskell-on-this-web-page">Using Haskell on this web page</a></li>
<li><a href="#glasgow-haskell-compiler">Glasgow Haskell Compiler</a><ul>
<li><a href="#installing-ghc">Installing GHC</a></li>
<li><a href="#using-ghci">Using GHCi</a></li>
<li><a href="#using-ghc">Using GHC</a></li>
</ul></li>
<li><a href="#text-editors">Text editors</a></li>
</ul>
</div>
<section id="what-is-a-programming-language" class="level1">
<h1>What is a programming language?</h1>
<p>A programming language is a system for describing the behavior of a computer.</p>
<p>That is, a programming language lets us tell a computer what we want it to do. This description is called <em>code</em>. It is the programmer’s job to write code.</p>
<p>When the computer performs based on the code, it is <em>executing</em> the code. For executing, we use a <em>compiler</em> or an <em>interpreter</em>, programs that understand the code.</p>
</section>
<section id="what-is-haskell" class="level1">
<h1>What is Haskell?</h1>
<p>Haskell is a programming language. In this class, you will learn its basics.</p>
<p>If Haskell is your first programming language, don’t worry. Haskell is famous for its elegance. We do not assume any previous programming experience. Some background in certain mathematical concepts, such as logic and induction, while not necessary, will be helpful.</p>
<p>If you have previously programmed with imperative languages such as C++, Java, or Python, you will find Haskell very different. Many aspects which cause difficulties for beginners in imperative language, such as memory allocation, pointers, <em>for</em> loops, and classes, are of much less importance in Haskell. On the other hand, you will have to learn new abstractions and new ways of approaching problems. We hope that this challenge is fun and will make you better programmers.</p>
</section>
<section id="how-is-haskell-different" class="level1">
<h1>How is Haskell different?</h1>
<p>If you’ve worked with imperative languages (C++, Java, Python, etc) in the past, Haskell may surprise you. Here are some key ways that Haskell is different:</p>
<ul>
<li><em>Functional</em>. Whereas imperative languages express programs as a sequence of command, to be executed in order, a Haskell program is expressed as mathematical functions. It thus avoids the state implicit in imperative programs. The functional nature of the language also means that instead of using the familiar <em>for</em> loop, most loops in Haskell are recursive.</li>
<li><em>Pure</em>. A Haskell program is concerned with manipulating values through functions, and not with performing stateful operations. Therefore, working with files, displaying output on the screen, and other inherently I/O-based operations are not part of the core language.</li>
<li><em>Lazy</em>. In Haskell, operations and not performed until their result is needed. This has some interesting consequences, such as the fact that in Haskell it is possible to work with lists of infinite length.</li>
<li>No pointers. Unlike C and C++, there are no pointers in Haskell, thereby eliminating a source of frequent programmer errors.</li>
<li>Excellent libraries. <a href="http://hackage.haskell.org/">Hackage</a> provides a repository of much useful code which can be easily and freely integrated into your programs.</li>
</ul>
</section>
<section id="using-haskell-on-this-web-page" class="level1">
<h1>Using Haskell on this web page</h1>
<p>For in-class exercises and for practicing at home, you can write Haskell code directly into special fields on the web page. When you press Enter, your code will be executed by an interpreter, and the result (and its type) will be displayed. If there was an error in your code, the error message will be displayed instead of the result.</p>
<p>Try experimenting with the field below. You can modify the code, and press Enter to evaluate it.</p>
<form class="resetinterpreter" action="javascript:getOne('c=eval&amp;f=AboutHaskell_en.hs','7f2918fc5b39cc0d287994ee1fa36917','7f2918fc5b39cc0d287994ee1fa36917');"><code class="prompt">Test&gt; </code><input class="interpreter" type="text" size="80" id="tarea7f2918fc5b39cc0d287994ee1fa36917" value="reverse &quot;Hello&quot;" /><br /><div class="answer" id="res7f2918fc5b39cc0d287994ee1fa36917"><code class="result">&quot;olleH&quot;</code><code> :: </code><code class="type">[Char]</code></div></form>
<p>The green text shows the value of the result of the code; in this case, <code>&quot;olleH&quot;</code>. The blue text shows the type of this result; in this case <code>[Char]</code>, or a list of characters.</p>
<p>Although a useful learning tool, this <em>in situ</em> usage has some important limitations:</p>
<ul>
<li>It is not appropriate for writing larger programs.</li>
<li>Infinite results can’t be displayed.</li>
<li>A time limit is enforced for calculations.</li>
<li>You can’t save your code for later.</li>
<li>You can’t write certain kinds of programs (e.g. side-effectful).</li>
<li>You can’t use arbitrary Haskell libraries.</li>
<li>You can’t write modules.</li>
</ul>
</section>
<section id="glasgow-haskell-compiler" class="level1">
<h1>Glasgow Haskell Compiler</h1>
<p>For writing full-fledged, stand-alone programs in Haskell, you should use the Glasgow Haskell Compiler (GHC). With GHC, you can avoid the limitations of code evaluation on this web site.</p>
<p>You can install GHC directly on your own computer, and you can use it even when you aren’t connected to the Internet. You can use GHC to create real programs that you can share with others.</p>
<section id="installing-ghc" class="level2">
<h2>Installing GHC</h2>
<p>If you are using Linux, installing GHC through your package manager is easy. Just run:</p>
<ul>
<li><code>sudo apt-get install ghc</code> (on Debian-ish distros)</li>
<li><code>sudo yum install ghc</code> (on Red Hat-ish distros)</li>
</ul>
<p>If you are using Windows or MacOS, you can download and install the <a href="http://www.haskell.org/platform/">Haskell Platform</a> from the web.</p>
</section>
<section id="using-ghci" class="level2">
<h2>Using GHCi</h2>
<p>Once you’ve installed GHC, you can immediately try it out using GHCi, the interactive interface to GHC. When you run GHCi, you will see a <code>Prelude&gt;</code> prompt. From here, you can type a Haskell expression to evaluate it. Also, you can:</p>
<ul>
<li>Use <code>let</code> to define a function.</li>
<li>Use <code>data</code>, <code>type</code>, or <code>newtype</code> to define a data type.</li>
<li>Use <code>:t</code> or <code>:type</code> to query the type of an expression.</li>
<li>Use <code>:q</code> or <code>:quit</code> to leave GHCi.</li>
<li>Use <code>:?</code> for a list of other commands.</li>
</ul>
</section>
<section id="using-ghc" class="level2">
<h2>Using GHC</h2>
<p>GHC, as a compiler, converts <em>source code</em> files into <em>executable</em> files.</p>
<p>Source code is a file containing Haskell code. You can create source code using any text editor. Haskell source code files typically have a suffix <code>.hs</code>.</p>
<p>An executable file is a program file that can be run by your computer’s operating system, e.g. by clicking on it or typing its name as a command.</p>
<p>Assuming that you have a source code file named <code>Test.hs</code>, you can compile (translate) that file using the following command:</p>
<pre><code>ghc Test.hs</code></pre>
<p>The above command will produce a new file named <code>Test</code> (or <code>Test.exe</code> on Windows) that you can run.</p>
</section>
</section>
<section id="text-editors" class="level1">
<h1>Text editors</h1>
<p>For editing source code, you must use a text editor. There are many text editors, each with different features and usability. While some are better than others, you may use any of them. Students already familiar with programming may prefer to use a programmer’s editor or IDE; while students who have not programmed may prefer a simpler editor. Please use whichever editor works best for you.</p>
<ul>
<li>Notepad (comes with Windows)</li>
<li><a href="https://wiki.gnome.org/Apps/Gedit">gedit</a> (comes with GNOME Linux distros)</li>
<li><a href="http://kate-editor.org/">Kate</a> (comes with KDE Linux distros)</li>
<li><a href="http://notepad-plus-plus.org/">Notepad++</a></li>
<li><a href="http://www.sublimetext.com/">SublimeText</a></li>
<li><a href="https://www.eclipse.org/">Eclipse</a></li>
<li><a href="http://macromates.com/">TextMate</a></li>
<li><a href="http://www.gnu.org/software/emacs/">Emacs</a> (for advanced users only)</li>
<li><a href="http://www.vim.org/">Vim</a> (for advanced users only)</li>
<li><a href="http://leksah.org/">Leksah</a></li>
</ul>
<p>Please note that word processors, such as Microsoft Word, are not text editors, and are <strong>not</strong> appropriate for editing source code.</p>
</section>
</body>
</html>

