This file contains 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 Expressions where | |
import qualified Data.Map as M | |
import Text.Printf | |
import Control.Monad | |
import qualified Control.Monad.Error as E | |
testExpr = (Op Sum (Val 1) (Symbol "x")) | |
type Value = Either Error Int |
This file contains 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 Data.Maybe | |
import Text.Printf | |
import Control.Applicative | |
data Expr = Term Int | Op Operator Expr Expr | Var String | |
deriving (Show, Eq) | |
data Operator = Sum | Mult | Sub | Div | |
deriving (Show, Eq) | |
This file contains 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 query-comprehension | |
(:use clojure.contrib.prxml)) | |
;; | |
;; Enhanced List Comprehensions supporting arbitary group-by, filtering and ordering. | |
;; | |
;; (from [ BINDING GENERATOR -- One or more Generator clauses | |
;; :when PREDICATE ] -- Zero or more Guards | |
;; :group-by [ EXPRESSION :into [KEY_NAME GROUP_NAME]] -- Optional Group-By qualifier | |
;; :having PREDICATE -- Optional Group Guard |
This file contains 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 Main where | |
import Text.Printf | |
import Data.List | |
profit :: Int -> Int -> [Int] -> Int | |
profit cap rides groups | |
| sum groups <= cap = rides * sum groups | |
| otherwise = | |
case toCaps . findCycle $ rideCaps cap rides groups of |
This file contains 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. | |
;; |
This file contains 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 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 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 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 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’); | |
* } |
OlderNewer