$30 off During Our Annual Pro Sale. View Details »

Haskell Talk

Haskell Talk

A TechTalk for the SSE

Chris Bentivenga

December 20, 2012
Tweet

Other Decks in Technology

Transcript

  1. Haskell is a computer programming language. In particular, it is

    a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. http://www.haskell.org/haskellwiki/Introduction Thursday, December 20, 12
  2. Polymorphically Statically Typed •id :: a -> a •Char ->

    Char • Int -> Int • Bool -> Bool Thursday, December 20, 12
  3. Lazy • Not evaluated when bound • Evaluated when executed

    • take 5 [1..] • [1,2,3,4,5] Thursday, December 20, 12
  4. Purely Functional • Imperative (OO, Procedural): • Execute statements •

    Change state • Functional: • Evaluate expressions • No state Thursday, December 20, 12
  5. Features of Functional Languages • High Order Functions • Purity

    • Lazy Execution • Recursion Thursday, December 20, 12
  6. Purity • No side effects • Is no state •

    A function, given the same input will always return the same output • Haskell does have monads • Used to simulate side effects Thursday, December 20, 12
  7. Lazy • Not evaluated when bound • Evaluated when executed

    • take 5 [1..] • [1,2,3,4,5] Already Saw This! Thursday, December 20, 12
  8. Recursion • Same as recursion in any other paradigim •

    One of the few ways to iterate • Is no for loop Thursday, December 20, 12
  9. 3 Haskell Commands • ghc • Compiler (gcc, g++) •

    ghci • Interactive (python <no args>, irb) • REPL • runghc • Run as interpreted (python <file>, ruby) Thursday, December 20, 12
  10. Haskell Basics • Entry point: main function (like C, C++)

    • Basic output function: print Thursday, December 20, 12
  11. Silly Silly Haskell Notation • $ -- Function Applicator •

    . -- Function Composition Thursday, December 20, 12
  12. Currying • Partially fill out the parameters on a function

    • Creates a new function that expects fewer paramaters Thursday, December 20, 12
  13. Parameters • Functions technically can’t have more then one parameter

    • A function with two parameters is technically a function that returns a function that accepts a parameter... Thursday, December 20, 12
  14. Typing System • Strictly typed under the hood • Don’t

    have to see those types • Can explicitly write out types on a function Thursday, December 20, 12
  15. /Users/chris/projects/haskell_talk/Types/types.hs:4:10: Couldn't match expected type `Int' with actual type `[Char]'

    In the first argument of `f', namely `"123"' In the expression: f "123" In an equation for `main': main = f "123" Thursday, December 20, 12
  16. Lists • Standard functional data structure • List operations: map,

    filter, reduce, etc... Thursday, December 20, 12
  17. Pattern Matching • Function headers have portions already declared •

    Maps to the most fitting portion Thursday, December 20, 12