Haskell - PowerPoint PPT Presentation

About This Presentation
Title:

Haskell

Description:

Types are checked at compile-time. Types cannot be ... Every checkout is a branch. Every checkout is a repository. Darcs - interactive. Interactive 'pull' ... – PowerPoint PPT presentation

Number of Views:135
Avg rating:3.0/5.0
Slides: 24
Provided by: arob
Learn more at: http://www.calug.org
Category:
Tags: checkout | haskell

less

Transcript and Presenter's Notes

Title: Haskell


1
Haskell
  • programming language

2
Haskell is
  • Memory managed (allocation, collection)
  • Typeful (static, strong)
  • Types are checked at compile-time
  • Types cannot be coerced (in general)
  • Pure functional programming
  • Emphasis on functions
  • Referential transparency
  • All variables are constant

3
Haskell - pros cons
  • Concurrency
  • The 1 on Language Shootout for threading
  • All non-I/O code is concurrent by default
  • (mutations are handled as I/O code)
  • Readability
  • No parentheses or commas
  • Higher-order functions reduce lines-of-code
  • (no syntax as a reminder of context)

4
Haskell - namespaces
  • Main
  • main
  • True
  • a
  • Bool
  • Eq
  • -- modules (packages)
  • -- value variables (functions)
  • -- value constructors
  • -- type variables (generics)
  • -- type constructors
  • -- type classes (interfaces)

5
Haskell - syntax
  • Derived syntax
  • f x expr
  • (x )
  • ( y)
  • ()
  • x times y
  • f g h x
  • (f . g . h) x
  • do a b c
  • -- lambda
  • -- sections
  • -- sections
  • -- sections
  • -- infix func
  • -- parens
  • -- compose
  • -- I/O bind

Core syntax f \x -gt expr \y -gt x y \x -gt x
y \x y -gt x y times x y f (g (h x)) f (g (h
x)) a gtgt b gtgt c
6
Haskell - type syntax
  • life 42 Int
  • life Int
  • life 42

7
Haskell - types
  • Hello String
  • length a -gt Int
  • floor Float -gt Int
  • map (a -gt b) -gt a -gt b
  • 42 Int
  • () Int -gt Int -gt Int
  • 42 Num a gt a
  • () Num a gt a -gt a -gt a

8
Haskell - type system
  • Int, Word, Float, Double, Char
  • type String Char
  • data Maybe a Nothing Just a
  • class Eq a where
  • (), (/) a -gt a -gt Bool
  • instance Eq Bool where
  • True True True
  • False False True
  • _ _ False
  • -- built-in types
  • -- type synonyms
  • -- data types
  • -- type classes
  • -- type class instances

9
Haskell - datatypes
  • data Bool False True
  • data Tree a Leaf a
  • Branch (Tree a) (Tree a)
  • data Rect Rect Int Int Int Int
  • data Rect Rect
  • x, y Int,
  • width Int,
  • height Int
  • -- enumerations
  • -- generics
  • -- unlabeled record
  • -- labeled record

10
Haskell - example programs
  • main return ()
  • main putStrLn Hello World
  • main interact id
  • main interact
  • (unlines . reverse . lines)
  • main do
  • args lt- getArgs
  • case args of
  • "-n"a -gt putStr (unwords a)
  • a -gt putStrLn (unwords a)
  • -- null program
  • -- hello world
  • -- UNIX cat
  • -- GNU tac
  • -- UNIX echo

11
  • version control system

12
Darcs - overview
  • The Theory of Patches
  • A branch is a set of patches
  • Spontaneous branches
  • Every checkout is a branch
  • Every checkout is a repository

13
Darcs - interactive
  • Interactive pull
  • You chose what patches to download
  • Interactive push
  • You chose what patches to commit externally
  • Interactive record
  • You chose what files to commit locally

14
Parsec
  • parser library

15
Parsec - combinators
  • many Parser a -gt Parser a
  • many1 Parser a -gt Parser a
  • optional Parser a -gt Parser (Maybe a)
  • sepBy Parser a -gt Parser s -gt Parser a
  • sepBy1 Parser a -gt Parser s -gt Parser a
  • endBy Parser a -gt Parser s -gt Parser a
  • endBy1 Parser a -gt Parser s -gt Parser a
  • char Char -gt Parser Char
  • between Parser open
  • -gt Parser close
  • -gt Parser a -gt Parser a
  • -- like regex
  • -- like regex
  • -- like regex?
  • -- ... , ... , ...
  • -- ... ... ...
  • -- c
  • -- lt ... gt

16
Parsec - example parsers
  • number many digit
  • string between
  • (char ")
  • (char ")
  • (many anyChar)
  • lisp number
  • ltgt string
  • ltgt identifier
  • ltgt parens many lexeme lisp

17
xmonad
  • X11 window manager

18
XMonad - overview
  • Tilling window manager (like Ratpoison)
  • Libraries of extensions and status bars
  • Customizable (config file is the app)
  • Full keyboard accessibility

19
XMonad - example config
  • module Main where
  • import XMonad
  • import System.Exit
  • import qualified XMonad.StackSet as W
  • import qualified Data.Map as M
  • myKeys conf_at_(XConfig XMonad.modMask modMask)
    M.fromList
  • ((modMask .. shiftMask, xK_Return), spawn
    XMonad.terminal conf),
  • ((modMask .. shiftMask, xK_q ), io
    (exitWith ExitSuccess))
  • myMouseBindings (XConfig XMonad.modMask
    modMask) M.fromList
  • ((modMask, button1), (\w -gt focus w gtgt
    mouseMoveWindow w)),
  • ((modMask, button2), (\w -gt focus w gtgt
    windows W.swapMaster)),
  • ((modMask, button3), (\w -gt focus w gtgt
    mouseResizeWindow w))
  • defaults defaultConfig
  • keys myKeys,
  • mouseBindings myMouseBindings,

20
Yi
  • extensible text editor

21
Yi - overview
  • Extensible
  • Fully dynamic application (hs-plugins)
  • All state is serialized and reloaded
  • Customizable
  • yi --asvim (for vim key bindings)
  • yi --asemacs (for emacs key bindings)

22
Yi - structure
Taken from lthttp//www.cse.unsw.edu.au/dons/paper
s/SC05.htmlgt
23
Haskell
  • Thank You
Write a Comment
User Comments (0)
About PowerShow.com