summaryrefslogtreecommitdiffstats
path: root/software/haskell.page
diff options
context:
space:
mode:
Diffstat (limited to 'software/haskell.page')
-rw-r--r--software/haskell.page62
1 files changed, 62 insertions, 0 deletions
diff --git a/software/haskell.page b/software/haskell.page
new file mode 100644
index 0000000..8e7d9f8
--- /dev/null
+++ b/software/haskell.page
@@ -0,0 +1,62 @@
+
+Haskell
+==================
+
+Structure
+------------
+Haskell programs consist of monads, actions, modules, ???
+
+Basic Syntax
+---------------
+
+A "type declaration":
+
+ main :: IO ()
+
+An action definition. Note that whitespace matters; the block extends to all
+lines indented to the same position as the first non-whitespace after the
+``do``:
+
+ main = do
+ stuff1
+ stuff2
+
+Lists
+--------
+Lists in haskell are homogenous: all elements must of the same type. They are
+linked lists, so cons-ing on the front is cheap and concatonating on the end
+can be expensive.
+
+Use ++ to concatonate two lists together:
+
+ ['a','b','c'] ++ ['d','e','f']
+
+Use : to cons (prepend) a single element:
+
+ 0:[1,2,3,4,5,6]
+
+Use !! to pull out an element by index (zero indexed):
+
+ ['c','a','t'] !! 1
+
+Strings are lists of characters: "baby" is equivalent to ['b','a','b','y'],
+which is equivalent to 'b':'a':'b':'y':[]. The empty set is [] and is distinct
+from [[]].
+
+A couple functions help; 'head' is like 'car' and gives the first element,
+'tail' is like 'cdr' and gives everything except the first element, 'last'
+gives the last non-empty element, and 'init' gives everything except the
+'last'. 'length' gives the number of elements, 'null' is a test to see if this
+is the empty list,
+
+Compilation
+------------
+By default the "main" action of the "Main" module is the action that is
+executed when a compiled haskell program is run by the operating system;
+this means that most haskell programs need to define these components.
+
+The `ghc` (Glasgow Haskell Compiler) is the most popular. To compile and
+execute a simple one file haskell program you will do something like:
+
+ ghc -o hello helloworld.hs
+ ./hello