Skip to content

Instantly share code, notes, and snippets.

@ejconlon
ejconlon / haskds.md
Last active December 15, 2016 04:32
Simple data science operations in Haskell

Simple data science operations in Haskell

Simple tasks

  1. Read a table of data from disk

Cassava: exploratory CSV parsing

@ejconlon
ejconlon / package.scala
Last active August 29, 2015 14:26
Elm Tasks, in Scala
package object tasks {
trait Task[A, B] {
private[tasks] def run(): Either[A, B]
def map[C](f: B => C): Task[A, C] = ???
def flatMap[C](f: B => Task[A, C]): Task[A, C] = ???
}
private[tasks] class Http[A, B](
data: HttpRequest,
handler: Either[Throwable, HttpResponse] => Either[A, B],
@ejconlon
ejconlon / sudoku.hs
Created May 20, 2011 05:13
Project Euler 96 - Solve Sudoku! (in Haskell)
#!/usr/bin/env runhaskell
{- Project Euler 96 - Solve Sudoku!
-
- Compile it with ghc -o blah --make sudoku
-
- And grab sudoku.txt from
- http://projecteuler.net/index.php?section=problems&id=96
-
- Answer: 24702
@ejconlon
ejconlon / annotree.hs
Created May 20, 2011 04:35
Monad-like trees with fun applications like integer factoring
#!/usr/bin/env runhaskell
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeSynonymInstances, FunctionalDependencies #-}
{- Monad-like trees can do cool things like factoring integers and
- pruning leaves with bind (>>=).
-
- Internal nodes are annotated with a measure of some sort that can be used
- for efficient indexing and sizing.
-
- Measured typeclass and tagged nodes from
@ejconlon
ejconlon / pyreactor.py
Created February 27, 2011 03:26
Translated from the example in "Deprecating the Observer Pattern" (Maier, Rompf, Odersky)
#!/usr/bin/env python
"""
Translated from the example in
Deprecating the Observer Pattern (Maier, Rompf, Odersky)
http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf
Their Scala example:
Reactor.once { self =>
// step 1:
@ejconlon
ejconlon / trampoline.py
Created January 30, 2011 05:03
Tail-Recursion helper in Python
#!/usr/bin/env python
"""
Tail-Recursion helper in Python.
Inspired by the trampoline function at
http://jasonmbaker.com/tail-recursion-in-python-using-pysistence
Tail-recursive functions return calls to tail-recursive functions
(themselves, most of the time). For example, this is tail-recursive: