Haskell programming language Haskell is l l Memory

  • Slides: 23
Download presentation
Haskell programming language

Haskell programming language

Haskell is… l l Memory managed (allocation, collection) “Typeful” (static, strong) – – l

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

Haskell - pros & cons l Concurrency – – – l The #1 on

Haskell - pros & cons l Concurrency – – – l 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)

Haskell - namespaces l l l Main main True a Bool Eq -- modules

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

Haskell - syntax Derived syntax Core syntax f x = expr (x *) (*

Haskell - syntax Derived syntax Core syntax f x = expr (x *) (* y) (*) x `times` y f $ g $ h x (f. g. h) x do a; b; c f = x -> expr y -> x * y x y -> x * y times x y f (g (h x)) a >>= b >>= c -- lambda -- sections -- infix func -- parens -- compose -- I/O bind

Haskell - type syntax life = 42 : : Int life = 42

Haskell - type syntax life = 42 : : Int life = 42

Haskell - types “Hello” : : String length : : [a] -> Int floor

Haskell - types “Hello” : : String length : : [a] -> Int floor : : Float -> Int map : : (a -> b) -> [a] -> [b] 42 : : Int (+) : : Int -> Int 42 : : Num a => a (+) : : Num a => a -> a

Haskell - type system Int, Word, Float, Double, Char -- built-in types type String

Haskell - type system Int, Word, Float, Double, Char -- built-in types type String = [Char] -- type synonyms data Maybe a = Nothing | Just a -- data types class Eq a where (==), (/=) : : a -> Bool -- type classes instance Eq Bool True == True False == False _ == _ -- type class instances where = True = False

Haskell - datatypes data Bool = False | True -- enumerations data Tree a

Haskell - datatypes data Bool = False | True -- enumerations data Tree a = Leaf a | Branch (Tree a) -- generics data Rect = Rect Int Int -- unlabeled record data Rect = Rect { x, y : : Int, width : : Int, height : : Int} -- labeled record

Haskell - example programs main = return () -- null program main = put.

Haskell - example programs main = return () -- null program main = put. Str. Ln “Hello World” -- hello world main = interact id -- UNIX cat main = interact (unlines. reverse. lines) -- GNU tac main = do args <- get. Args case args of "-n": a -> put. Str (unwords a) a -> put. Str. Ln (unwords a) -- UNIX echo

version control system

version control system

Darcs - overview l l l Theory of Patches A “branch” is a set

Darcs - overview l l l Theory of Patches A “branch” is a set of patches “Spontaneous branches” Every checkout is a branch Every checkout is a repository

Darcs - interactive l Interactive “pull” – l Interactive “push” – l You chose

Darcs - interactive l Interactive “pull” – l Interactive “push” – l You chose what patches to download You chose what patches to commit externally Interactive “record” – You chose what files to commit locally

Parsec parser library

Parsec parser library

Parsec - combinators many : : Parser a -> Parser [a] many 1 :

Parsec - combinators many : : Parser a -> Parser [a] many 1 : : Parser a -> Parser [a] optional : : Parser a -> Parser (Maybe a) -- like regex* -- like regex+ -- like regex? sep. By : : Parser a -> Parser s -> Parser [a] --. . . , . . . sep. By 1 : : Parser a -> Parser s -> Parser [a] end. By : : Parser a -> Parser s -> Parser [a] --. . . ; end. By 1 : : Parser a -> Parser s -> Parser [a] char : : Char -> Parser Char between : : Parser open -> Parser close -> Parser a -- c -- <. . . >

Parsec - example parsers number = many digit string = between (char ‘"’) (many

Parsec - example parsers number = many digit string = between (char ‘"’) (many any. Char) lisp = number <|> string <|> identifier <|> parens $ many $ lexeme lisp

xmonad X 11 window manager

xmonad X 11 window manager

XMonad - overview l l Tilling window manager (like Ratpoison) Libraries of extensions and

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

XMonad - example config module Main where import XMonad System. Exit qualified XMonad. Stack.

XMonad - example config module Main where import XMonad System. Exit qualified XMonad. Stack. Set as W qualified Data. Map as M my. Keys conf@(XConfig {XMonad. mod. Mask = mod. Mask}) = M. from. List $ [ ((mod. Mask. |. shift. Mask, x. K_Return), spawn $ XMonad. terminal conf), ((mod. Mask. |. shift. Mask, x. K_q ), io (exit. With Exit. Success))] my. Mouse. Bindings (XConfig ((mod. Mask, button 1), ((mod. Mask, button 2), ((mod. Mask, button 3), {XMonad. mod. Mask = (w -> focus w >> defaults = default. Config { keys = my. Keys, mouse. Bindings = my. Mouse. Bindings, terminal = "xterm"} main = xmonad defaults mod. Mask}) = M. from. List $ [ mouse. Move. Window w)), windows W. swap. Master)), mouse. Resize. Window w))]

Yi extensible text editor

Yi extensible text editor

Yi - overview l Extensible – – l Fully dynamic application (hs-plugins) All state

Yi - overview l Extensible – – l Fully dynamic application (hs-plugins) All state is serialized and reloaded Customizable – – yi --as=vim (for vim key bindings) yi --as=emacs (for emacs key bindings)

Yi - structure Taken from <http: //www. cse. unsw. edu. au/~dons/papers/SC 05. html>

Yi - structure Taken from <http: //www. cse. unsw. edu. au/~dons/papers/SC 05. html>

Haskell Thank You

Haskell Thank You