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
#include "dict.h" | |
/* Initializes the hash table at table. | |
* Arguments: | |
* | |
* init_size: the initial number of chains in the hash table. If 0, defaults | |
* to a hardcoded value. | |
* key_hash: a hashing function that operates on keys | |
* key_eq: function which returns nonzero iff two keys are equal. | |
* |
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.Monad | |
import Control.Monad.Identity (runIdentity) | |
import Control.Monad.Error | |
import Control.Monad.State.Lazy | |
import Data.Maybe (listToMaybe) | |
-- |Monad transformer which stores a stack internally | |
type StackT s m = StateT [s] 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
/** Game rules for state space S and players in P */ | |
trait GameRules[S, P] { | |
/** Score a position relative to a player. That is, a better | |
position should have a bigger score than a worse one. */ | |
def children(position: S): List[S] | |
def turn(position: S): P // Whose turn is it on some position? | |
} | |
/** Scores positions for a Strategy. R should have a total ordering (see the | |
* signature of pickMove below) and should be positive if the given player has |
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
interface MaybeVisitor<A, R> { | |
public R just(A v); | |
public R nothing(); | |
} | |
interface Maybe<A> { | |
public <R> R fold(MaybeVisitor<A, R> visitor); | |
} | |
interface PairVisitor<A, B, R> { |
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 KindSignatures, GADTs #-} | |
-- Inspired by the Well-Typed "Monads for Free!" slides, available online | |
data Free :: (* -> *) -> * -> * where | |
Return :: a -> Free f a | |
Wrap :: f (Free f a) -> Free f a | |
instance Functor f => Functor (Free f) where | |
fmap f (Return x) = Return (f x) |
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 MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, ScopedTypeVariables #-} | |
module TuringMachine where | |
import Control.Monad.State.Lazy | |
import Data.Array.ST | |
import Data.Array | |
import Data.Default | |
import Control.Monad.ST | |
import Control.Arrow ((&&&)) |
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 Stack where | |
import Control.Arrow | |
class List a | |
-- Use pairs to represent a cons list which can be statically checked | |
instance List () | |
instance List b => List (a, b) |
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.Word | |
import Data.List | |
import Control.Monad.State.Strict | |
import Control.DeepSeq | |
data EmitterState = EmitterState { | |
emNextLabel :: Int | |
} deriving (Read, Show, Eq, Ord) | |
instance NFData EmitterState where |
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
# why do blocks even exist? | |
def fibs1 | |
a, b = 0, 1 | |
while b < 1000 | |
yield b | |
a, b = b, a + b | |
end | |
end | |
# it seems like "yield" is just syntax for "invoke this weird callback" |
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
from __future__ import division | |
import sys | |
from random import SystemRandom | |
# A list of unicode combining characters | |
COMBINING = [unichr(c) for c in xrange(0x300, 0x370)] | |
ZalgoError = KeyError |