VU 183.653 Methodical, industrial Software-Engineering using the Haskell functional programming language

2013-03-18

Haskell Implementations

Haskell Platform

Editing Haskell Source

Compile & Run Haskell Programs

Haskell Language Report

Haskell 2010: What's new since Haskell 98?

Integrates a couple of widely used language extensions such as:

Haskell 2010: What's new since Haskell 98?

...but also support for some misfeatures is removed/deprecated:

Simple Functions

The following simple function already shows many language properties:

filter :: (a -> Bool) -> [a] -> [a]
filter p []    = []
filter p (x:xs)
  | p x        = x : filter p xs
  | otherwise  = filter p xs

User-defined Fixity

Basic Types

Basic Types

Weak Head Normal Form

Bottom

Partial vs. Total Functions

seq

User Definable Types

Strict Data Fields

Kinds

Parametric Polymorphism

Type-classes

Typeclass Example: NFData

Typeclass Example: NFData (cont.)

Module System

Module System (cont.)

Simple example showing some features:

Module Foo.Bar (module Foo.Bar.Doo, head, f1, f2,
                T1, T2(C1), T3(..)) where

import Foo.Bar.Doo            -- re-exported as-is
import Foo.Bar.Zoo (f1)       -- f1 is re-exported
import qualified Data.Bar.Zoo as Zoo
import Prelude hiding (head)

data T1 = HiddenConstr        -- only T1 is exported
data T2 = C1 | C2             -- only T2 and C1 is exported
data T3 = D1 | D2 | D3        -- complete type exported

f2 x = Zoo.f2 $! x

head :: [a] -> Maybe a
head []     = Nothing
head (x:_)  = x

Impure Computations

do Notation

The IO type

The IO type (cont.)

The IO type (cont.)

Haskell Kernel Sub-Language

Into which language subset can Haskell 98 be desugared?

Haskell kernel Sub-Language (cont.)

The Haskell Language Report refers to a

Haskell kernel Sub-Language (cont.)

For instance, the if/else expression

if e1 then e2 else e3

is simplified into...

Haskell kernel Sub-Language (cont.)

For instance, the if/else expression

if e1 then e2 else e3

is simplified into

case e1 of { True -> e2 ; False -> e3 }

Haskell kernel Sub-Language (cont.)

An infix function definition such as

True || _     = True
_    || True  = True
_    || _     = False

can be reduced to

(||) = \x1 x2 -> case (x1,x2) of { (True,_) -> True
                                 ; (_,True) -> True
                                 ; (_,_   ) -> False
                                 }

Later on, we'll discuss a similiar minimal language called "GHC Core".