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 Signal | |
import Window | |
(block_width, block_height) = (100, 100) | |
speed = 1.5 | |
dimensions = Window.dimensions | |
width = lift fst dimensions | |
height = lift snd dimensions |
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 type Functor = sig | |
type 'a t | |
val map : ('a -> 'b) -> 'a t -> 'b t | |
end | |
module type Monad = sig | |
type 'a t | |
val map : ('a -> 'b) -> 'a t -> 'b t | |
val return : 'a -> 'a t |
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
-- Standard Prelude definitions | |
-- data Ordering = LT | EQ | GT | |
-- class Eq a => Ord a where | |
-- compare :: a -> a -> Ordering | |
isOrdered :: Ord a => [a] -> Bool | |
isOrdered (x:y:xs) = case compare x y of | |
GT -> False | |
_ -> isOrdered (y:xs) | |
isOrdered _ = True |
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
module type FUNCTOR = sig | |
type 'v f | |
val map : ('a -> 'b) -> 'a f -> 'b f | |
end | |
module type MONAD = sig | |
type 'v f | |
val map : ('a -> 'b) -> 'a f -> 'b f | |
val pure : 'a -> 'a f | |
val join : ('a f) f -> 'a f |
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 |