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




3 download

Embed Size (px)


<ul><li><p>Haskellprogramming language</p></li><li><p>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</p></li><li><p>Haskell - pros &amp; 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)</p></li><li><p>Haskell - namespacesMainmainTrueaBoolEq-- modules (packages)-- value variables (functions)-- value constructors-- type variables (generics)-- type constructors-- type classes (interfaces)</p></li><li><p>Haskell - syntaxDerived syntax</p><p>f x = expr(x *)(* y)(*)x `times` yf $ g $ h x(f . g . h) xdo a; b; c</p><p>-- lambda-- sections-- sections-- sections-- infix func-- parens-- compose-- I/O bindCore syntax</p><p>f = \x -&gt; expr\y -&gt; x * y\x -&gt; x * y\x y -&gt; x * ytimes x yf (g (h x))f (g (h x))a &gt;&gt;= b &gt;&gt;= c</p></li><li><p>Haskell - type syntaxlife = 42 :: Int</p><p>life :: Intlife = 42</p></li><li><p>Haskell - typesHello :: Stringlength :: [a] -&gt; Intfloor :: Float -&gt; Intmap :: (a -&gt; b) -&gt; [a] -&gt; [b]</p><p>42 :: Int(+) :: Int -&gt; Int -&gt; Int</p><p>42 :: Num a =&gt; a(+) :: Num a =&gt; a -&gt; a -&gt; a</p></li><li><p>Haskell - type systemInt, Word, Float, Double, Char</p><p>type String = [Char]</p><p>data Maybe a = Nothing | Just a</p><p>class Eq a where (==), (/=) :: a -&gt; a -&gt; Bool</p><p>instance Eq Bool where True == True = True False == False = True _ == _ = False-- built-in types</p><p>-- type synonyms</p><p>-- data types</p><p>-- type classes</p><p>-- type class instances</p></li><li><p>Haskell - datatypesdata Bool = False | True</p><p>data Tree a = Leaf a | Branch (Tree a) (Tree a)</p><p>data Rect = Rect Int Int Int Int</p><p>data Rect = Rect { x, y :: Int, width :: Int, height :: Int}-- enumerations</p><p>-- generics</p><p>-- unlabeled record</p><p>-- labeled record</p></li><li><p>Haskell - example programsmain = return ()</p><p>main = putStrLn Hello World</p><p>main = interact id</p><p>main = interact (unlines . reverse . lines)</p><p>main = do args putStr (unwords a) a -&gt; putStrLn (unwords a)-- null program</p><p>-- hello world</p><p>-- UNIX cat</p><p>-- GNU tac</p><p>-- UNIX echo</p></li><li><p>version control system</p></li><li><p>Darcs - overviewThe Theory of PatchesA branch is a set of patchesSpontaneous branchesEvery checkout is a branchEvery checkout is a repository</p></li><li><p>Darcs - interactiveInteractive pullYou chose what patches to downloadInteractive pushYou chose what patches to commit externallyInteractive recordYou chose what files to commit locally</p></li><li><p>Parsecparser library</p></li><li><p>Parsec - combinatorsmany :: Parser a -&gt; Parser [a]many1 :: Parser a -&gt; Parser [a]optional :: Parser a -&gt; Parser (Maybe a)</p><p>sepBy :: Parser a -&gt; Parser s -&gt; Parser [a]sepBy1 :: Parser a -&gt; Parser s -&gt; Parser [a]</p><p>endBy :: Parser a -&gt; Parser s -&gt; Parser [a]endBy1 :: Parser a -&gt; Parser s -&gt; Parser [a]</p><p>char :: Char -&gt; Parser Charbetween :: Parser open -&gt; Parser close -&gt; Parser a -&gt; Parser a-- like regex*-- like regex+-- like regex?</p><p>-- ... , ... , ...</p><p>-- ... ; ... ; ... ;</p><p>-- c-- &lt; ... &gt;</p></li><li><p>Parsec - example parsersnumber = many digit </p><p>string = between (char ") (char ")(many anyChar)</p><p>lisp = number string identifier parens $ many $ lexeme lisp</p></li><li><p>xmonadX11 window manager</p></li><li><p>XMonad - overviewTilling window manager (like Ratpoison)Libraries of extensions and status barsCustomizable (config file is the app)Full keyboard accessibility</p></li><li><p>XMonad - example configmodule Main where</p><p>import XMonadimport System.Exitimport qualified XMonad.StackSet as Wimport qualified Data.Map as M</p><p>myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $ [ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf), ((modMask .|. shiftMask, xK_q ), io (exitWith ExitSuccess))]</p><p>myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $ [ ((modMask, button1), (\w -&gt; focus w &gt;&gt; mouseMoveWindow w)), ((modMask, button2), (\w -&gt; focus w &gt;&gt; windows W.swapMaster)), ((modMask, button3), (\w -&gt; focus w &gt;&gt; mouseResizeWindow w))]</p><p>defaults = defaultConfig { keys = myKeys, mouseBindings = myMouseBindings, terminal = "xterm"}</p><p>main = xmonad defaults</p></li><li><p>Yiextensible text editor</p></li><li><p>Yi - overviewExtensibleFully dynamic application (hs-plugins)All state is serialized and reloaded</p><p>Customizableyi --as=vim (for vim key bindings)yi --as=emacs (for emacs key bindings)</p></li><li><p>Yi - structureTaken from </p></li><li><p>HaskellThank You</p></li></ul>


View more >