Skip to content

Instantly share code, notes, and snippets.

View paf31's full-sized avatar

Phil Freeman paf31

View GitHub Profile
@paf31
paf31 / croco.hs
Last active December 15, 2015 21:48
Croco Magneto remake in Haskell
module Main where
import Data.List
import Data.Maybe
import Control.Monad
import qualified Graphics.Rendering.OpenGL as GL
import qualified Graphics.UI.GLUT as GLUT
import qualified Graphics.UI.GLUT.Callbacks.Window as W
import qualified Data.Map as M
import Graphics.UI.GLUT.State
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
@paf31
paf31 / Juggling.hs
Last active December 11, 2015 19:39
{-# LANGUAGE PolymorphicComponents, StandaloneDeriving #-}
module Juggling where
import Data.Bits
import Data.Maybe
import Control.Monad
import qualified Graphics.Rendering.OpenGL as GL
import qualified Graphics.UI.GLUT as GLUT
import qualified Graphics.UI.GLUT.Callbacks.Window as W
@paf31
paf31 / Siteswap.hs
Last active December 11, 2015 11:08
module Siteswap where
import Data.Bits
import Data.Maybe
import Control.Monad
newtype Height = Height { height :: Int } deriving (Show, Eq, Ord)
newtype Pattern = Pattern { pattern :: [Height] } deriving (Show, Eq)
@paf31
paf31 / marking.hs
Last active December 11, 2015 02:58
module MaxTree where
data Tree a = Tip | Branch a (Tree a) (Tree a)
maxSum :: Tree Int -> Int
maxSum t = let (_, w, wo) = maxSum' t in max w wo where
maxSum' :: Tree Int -> (Int, Int, Int)
maxSum' Tip = (0, 0, 0)
maxSum' (Branch n l r) =
let (lv, wl, wol) = maxSum' l in
module Liars where
import Control.Monad
import Data.List
data Person = Truthteller | Liar deriving (Show, Eq)
says :: Person -> Bool -> Bool
says Truthteller = id
says Liar = not
@paf31
paf31 / diff.hs
Last active December 10, 2015 01:09
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Function (on)
import Data.List (maximumBy)
class Container f where
@paf31
paf31 / random.hs
Created August 5, 2012 02:27
Testing Random Functions with Type Classes
module Random where
import System.Random (Random, randomRIO)
import Control.Monad.Identity (Identity, runIdentity)
import Data.Ratio
import Data.List (groupBy)
import Data.Function (on)
import Test.QuickCheck
newtype Stream m a = Stream { runStream :: m (Maybe (NonEmptyStream m a)) }
@paf31
paf31 / tunnel.html
Created August 2, 2012 17:56
tunnel.html
<!doctype html>
<html>
<head>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.globalAlpha = 0.5;
@paf31
paf31 / cube.html
Created August 2, 2012 17:55
cube.html
<!doctype html>
<html>
<head>
<script>
var x, y, z;
function to2d(v) {
return [