Skip to content

Instantly share code, notes, and snippets.

@futtetennista
Last active May 25, 2017 14:44
Show Gist options
  • Save futtetennista/ca5a65d3a66dc6e2789e69656d3e17a9 to your computer and use it in GitHub Desktop.
Save futtetennista/ca5a65d3a66dc6e2789e69656d3e17a9 to your computer and use it in GitHub Desktop.
Primer: Writing efficient code in a lazy language (Hamburg Haskell Meetup 2016-05-24)

Book

Topics

Models of reduction

Examples

In ghci:

sqr (6 + 5) -- innermost vs outermost evaluation
fst (6, undefined) -- innermost vs outermost evaluation
let a = [1..] :: [Integer] ; let b = map (+ 1) a ; a !! 6; b !! 11 ; :sprint a ; :sprint b

Exercises

  • ITFP 6.2.1, 6.2.2

Efficiency

Examples

In ghci:

:set -XBangPatterns

fst (1, undefined) -- 1
fst' (!a, !b) = a
fst' (1, undefined) -- 💥

length [undefined, 3, 4, 5] -- 4
-- 🤔 this didn't work in the live demo because I defined it as: g (!x:xs)= length (x:y:xs)
{ length' [] = 0; length' ((!x):xs)= length (x:xs) }
length' [undefined,3,4,5] -- 💥

Exercises

  • 6.3.3

Profiling in Haskell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment