Skip to content

Instantly share code, notes, and snippets.

@heath
Last active January 3, 2016 15:19
Show Gist options
  • Save heath/b1525f4c87d104546f65 to your computer and use it in GitHub Desktop.
Save heath/b1525f4c87d104546f65 to your computer and use it in GitHub Desktop.

TODO:

  • history of haskell
  • haskell modules
  • the fun parts

Haskell: compile-time dynamic programming

Time Traveling through Universes, or yet another Haskell Intro

A fun comparison

# Ruby version of quiksort

class Array
  def quick_sort
    return self if length <= 1
    pivot = self[0]
    less, greatereq = self[1..-1].partition { |x| x < pivot }
    less.quick_sort + [pivot] + greatereq.quick_sort
  end
end
-- Haskell version of quicksort
qsort [] = []
qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x]

Okay, it's not a fair comparison, but see more examples here: http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Haskell

Do notice that Haskell is generally shorter than other typed languages!

A bit of history

todo

A short intro to Haskell

Haskell is actually a simple language. Most of the ideas about the language will mostly be syntactic constructions derived from these concepts:

Haskell is a typed language, its types are:

  1. static
  2. strong
  3. inferred

Haskell is a functional language offering:

  1. purity: - given the same input, functions will always produce the same output (like mathematical functions)
  2. side-effect free programming: - a function's output is determined by its type
  3. laziness: - nothing is evaluated until it has to be evaluated
  4. higher order programming: - functions return functions and taking functions as input

Some fanboyism

Haskell programs typically have fewer bugs due to a few properties:

  1. Side-effect free programming: - no unintended consequences (i.e. side effects)
  2. Modularity: - Due to purity, functions can be versatily used across various programs and can always be expected perform the same.
  3. Strong types: - no dubious use of types ~= no core dumps
  4. Conciseness: - Programs are typically short.
  5. Memory Mangement: - The garbage collections allows you to worry about the correct problem: implementing the algorithm
  6. High level abstractions: - Haskell programs most often read exactly like the algorithm description

The fun parts

Possible topics include:

  • Category theory:
    • functors, monoids, and monads
  • ADTs
  • GADTs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment