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
tokenized_string = "2 + 3 * 4".split() | |
# parsing arithmetic expressions with + and * | |
# A parser returns (parsed_thing, new_index) on success. | |
def fail(): raise Exception("failed to parse") | |
def is_num(x): | |
try: int(x) | |
except ValueError: return False |
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 Control.Monad (mapM_) | |
import Data.List (intersperse) | |
import System.CPUTime | |
import Text.Printf | |
import qualified Data.Set as Set | |
import Text.Derp |
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 subprocess | |
import threading | |
import sys | |
the_cvar = threading.Condition(threading.RLock()) | |
turn = 0 | |
NTHREADS = 20 | |
WINDOW = 1 | |
ITERS = 100 |
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
?an:id can fly | |
= ?an is a bird | |
- ?an is a penguin | |
+ ?an is Harry the Rocket Penguin | |
// nb. left-associative; a - b + c = (a - b) + c. | |
safe path from ?a to ?c | |
= edge from ?a to ?c | |
+ (edge from ?a to ?b | |
- ?b is dangerous |
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
{-# LANGUAGE FlexibleInstances, DeriveGeneric #-} | |
-- http://design.perl6.org/S09.html#Junctions | |
module Junction where | |
import GHC.Generics | |
import Test.QuickCheck | |
import Control.Applicative | |
data Junction a = Pure a |
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 weird sort of recursive dataflow system? *) | |
module type FLOW = sig | |
type key | |
type 'a exp | |
(* applicative structure *) | |
val pure : 'a -> 'a exp | |
val (~) : ('a -> 'b) exp -> 'a exp -> 'b exp | |
(* lazily computing a fixed-point map *) |
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
THIS IS IRRELEVANT |
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
// each state element is of the form [value, bitmask, expression] | |
// - `expression` is a string representing an arithmetic expressoin | |
// - `value` is the arithmetic value of `expression` | |
// - `bitmask` is a bitmask recording which of the 4 numbers (6,6,5,2) we've | |
// used | |
const state = [[6,1,"6"],[6,2,"6"],[5,4,"5"],[2,8,"2"]]; | |
// combines compatible states using arithmetic operations to produce new states. | |
// | |
// x and y are states (see above) |
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
{-# LANGUAGE DatatypeContexts #-} | |
module Tmp where | |
data Ord a => Set a = Empty | |
| Single a | |
| Union (Set a) (Set a) | |
instance Monad Set where | |
return x = Single x -- type errors b/c can't find Ord instance |
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 Arithmetic where | |
import Data.Set hiding (map) | |
solve target inputs = [e | e <- exprs inputs, Just target == eval e] | |
-- Expressions | |
data Expr = Num Rational | Op Op Expr Expr deriving (Eq, Ord) | |
instance Show Expr where | |
show (Num n) = show n |
OlderNewer