Skip to content

Instantly share code, notes, and snippets.

@jameskeane
Created October 22, 2011 20:52
Show Gist options
  • Save jameskeane/1306481 to your computer and use it in GitHub Desktop.
Save jameskeane/1306481 to your computer and use it in GitHub Desktop.
Coffeescript + types + haskell = compiled language
=========
- Increments an infinite precision number, represented as a linked list with least significant digit as head
increment = (x: [Num]) ->
switch x
when [] then [1]
when (9::tail) then 0::increment(tail)
when (h::t) then (h+1)::t
- Increments an infinite precision number, represented as a linked list with least significant digit as head
decrement = (x: [Num]) ->
switch x
when [1] then []
when (0::tail) then 9::decrement(tail)
when (h::t) then (h-1)::t
- Quicksort
quicksort = (x: [Ord]) ->
switch x
when [] then []
when (h::t) then l
smallerSorted ++ [x] ++ biggerSorted
where
smallerSorted = quicksort [a | a <- t, a <= h]
biggerSorted = quicksort [a | a <- t, a > x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment