This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Concurrent.MVar | |
import Control.Monad.Fix (mfix) | |
import qualified Data.Map as M | |
fix :: (t -> t) -> t | |
fix f = f (fix f) | |
fib :: (Eq a, Num a) => (a -> a) -> a -> a | |
fib _ 0 = 0 | |
fib _ 1 = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Prelude hiding ((.), id) | |
import Control.Wire | |
import Control.Arrow | |
import Data.Set (Set) | |
import Data.Monoid | |
import qualified Data.Set as S | |
import qualified Graphics.UI.SDL as SDL | |
import qualified Graphics.UI.SDL.Image as SDLi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Process where | |
import Control.Monad.Reader | |
import Control.Monad.Cont | |
-- | this is the infinite stream of steps from the Bot, each step takes an environment | |
-- and yields a command and the entire rest of the computation | |
type Process = Reader DashBoard Step | |
data Step = Step { stepCmd :: Command, stepNext :: Process } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An example of lightweight (Green) application threads using the continuation monad, | |
* which gives us scalable non-blocking IO without nested callbacks. | |
* @author willtim | |
*/ | |
object GreenThreads { | |
// a thread (continuation) represents the rest of the computation | |
sealed abstract class Thread | |
case class Print(str: String, rest: Thread) extends Thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author willtim | |
* Purely functional version of Kernighan and Ritchie’s wc program | |
* | |
* #include <stdio.h> | |
* #define IN 1 /* inside a word */ | |
* #define OUT 0 /* outside a word */ | |
* int blank(int c) { | |
* return ( c==’ ’ || c==’\n’ || c==’\t’); | |
* } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A purely functional dataflow graph using Arrows. | |
* Note that the groupBy compbinator is built from the accum primitive. | |
* @author willtim | |
*/ | |
object Dataflow { | |
case class Auto[A,B] (run: A => (B, Auto[A,B])) { f => | |
def >>> [C] (g: Auto[B,C]): Auto[A,C] = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.State | |
import Control.Monad.Logic | |
import Data.List | |
import qualified Data.Map as M | |
type BindingT k v = StateT (M.Map k v) | |
bind :: (MonadPlus m, Ord k, Eq v) => k -> v -> BindingT k v m () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.core.match :only [match]]) | |
;; quick and simple trie implementation from the description | |
;; in the book "Purely Functional Data Structures" by Okasaki | |
(def empty-trie [:trie :value nil :edges {}]) | |
(defn lookup [key trie] | |
(match [key trie] | |
[[] [:trie :value nil :edges _]] nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IterateesHomework where | |
import Prelude hiding (words, unwords, init) | |
import Data.Text hiding (reverse, map, take) | |
import Data.Enumerator hiding (map) | |
import Control.Applicative ((<$>)) | |
import Data.List (sort) | |
import qualified Data.Enumerator.Binary as EB | |
import qualified Data.Enumerator.Text as ET | |
import qualified Data.Enumerator.List as EL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns willtim.clj-vtd-xml | |
(:import [com.ximpleware VTDGen VTDNav AutoPilot]) | |
(:require | |
[clojure.contrib.duck-streams :as ds])) | |
;; | |
;; Clojure API for VTD-XML | |
;; | |
;; Designed to work like clojure.contrib.zip-filter.xml, e.g. | |
;; |