Haskell programming language. Haskell is… Memory managed (allocation, collection) “Typeful” (static, strong) – Types are checked at compile-time – Types.

Download Haskell programming language. Haskell is… Memory managed (allocation, collection) “Typeful” (static, strong) – Types are checked at compile-time – Types.

Post on 12-Jan-2016

216 views

Category:

Documents

3 download

TRANSCRIPT

  • Haskellprogramming language

  • Haskell isMemory managed (allocation, collection)Typeful (static, strong)Types are checked at compile-timeTypes cannot be coerced (in general)Pure functional programmingEmphasis on functionsReferential transparencyAll variables are constant

  • Haskell - pros & consConcurrencyThe #1 on Language Shootout for threadingAll non-I/O code is concurrent by default(mutations are handled as I/O code)ReadabilityNo parentheses or commasHigher-order functions reduce lines-of-code(no syntax as a reminder of context)

  • Haskell - namespacesMainmainTrueaBoolEq-- modules (packages)-- value variables (functions)-- value constructors-- type variables (generics)-- type constructors-- type classes (interfaces)

  • Haskell - syntaxDerived syntax

    f x = expr(x *)(* y)(*)x `times` yf $ g $ h x(f . g . h) xdo a; b; c

    -- lambda-- sections-- sections-- sections-- infix func-- parens-- compose-- I/O bindCore syntax

    f = \x -> expr\y -> x * y\x -> x * y\x y -> x * ytimes x yf (g (h x))f (g (h x))a >>= b >>= c

  • Haskell - type syntaxlife = 42 :: Int

    life :: Intlife = 42

  • Haskell - typesHello :: Stringlength :: [a] -> Intfloor :: Float -> Intmap :: (a -> b) -> [a] -> [b]

    42 :: Int(+) :: Int -> Int -> Int

    42 :: Num a => a(+) :: Num a => a -> a -> a

  • Haskell - type systemInt, Word, Float, Double, Char

    type String = [Char]

    data Maybe a = Nothing | Just a

    class Eq a where (==), (/=) :: a -> a -> Bool

    instance Eq Bool where True == True = True False == False = True _ == _ = False-- built-in types

    -- type synonyms

    -- data types

    -- type classes

    -- type class instances

  • Haskell - datatypesdata 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

  • Haskell - example programsmain = return ()

    main = putStrLn Hello World

    main = interact id

    main = interact (unlines . reverse . lines)

    main = do args putStr (unwords a) a -> putStrLn (unwords a)-- null program

    -- hello world

    -- UNIX cat

    -- GNU tac

    -- UNIX echo

  • version control system

  • Darcs - overviewThe Theory of PatchesA branch is a set of patchesSpontaneous branchesEvery checkout is a branchEvery checkout is a repository

  • Darcs - interactiveInteractive pullYou chose what patches to downloadInteractive pushYou chose what patches to commit externallyInteractive recordYou chose what files to commit locally

  • Parsecparser library

  • Parsec - combinatorsmany :: Parser a -> Parser [a]many1 :: Parser a -> Parser [a]optional :: Parser a -> Parser (Maybe a)

    sepBy :: Parser a -> Parser s -> Parser [a]sepBy1 :: Parser a -> Parser s -> Parser [a]

    endBy :: Parser a -> Parser s -> Parser [a]endBy1 :: Parser a -> Parser s -> Parser [a]

    char :: Char -> Parser Charbetween :: Parser open -> Parser close -> Parser a -> Parser a-- like regex*-- like regex+-- like regex?

    -- ... , ... , ...

    -- ... ; ... ; ... ;

    -- c-- < ... >

  • Parsec - example parsersnumber = many digit

    string = between (char ") (char ")(many anyChar)

    lisp = number string identifier parens $ many $ lexeme lisp

  • xmonadX11 window manager

  • XMonad - overviewTilling window manager (like Ratpoison)Libraries of extensions and status barsCustomizable (config file is the app)Full keyboard accessibility

  • XMonad - example configmodule Main where

    import XMonadimport System.Exitimport qualified XMonad.StackSet as Wimport qualified Data.Map as M

    myKeys conf@(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 -> focus w >> mouseMoveWindow w)), ((modMask, button2), (\w -> focus w >> windows W.swapMaster)), ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))]

    defaults = defaultConfig { keys = myKeys, mouseBindings = myMouseBindings, terminal = "xterm"}

    main = xmonad defaults

  • Yiextensible text editor

  • Yi - overviewExtensibleFully dynamic application (hs-plugins)All state is serialized and reloaded

    Customizableyi --as=vim (for vim key bindings)yi --as=emacs (for emacs key bindings)

  • Yi - structureTaken from

  • HaskellThank You

Recommended

View more >