Skip to content

Instantly share code, notes, and snippets.

@isomorphism
isomorphism / Map.hs
Created May 12, 2013 00:55
Comments on code structure and style. My remarks are preceded by a ~ in the comments.
module Map
( RoomId, Connection
, Room(..), Map
, describeRoom
, numberRooms
, generateMap
, Wumpus (..)
) where
-- use a proper key/value lookup data structure instead of lists
@isomorphism
isomorphism / Euler12.hs
Created August 6, 2011 05:52
quick and stupid benchmarking example
import Data.List
import System.Environment
{- RE: http://stackoverflow.com/q/6964392/157360
cam@atomos:~/scraps/SO/euler$ ghc -O2 --make Euler12.hs
cam@atomos:~/scraps/SO/euler$ time ./Euler12 1000
842161320
real 0m12.892s
@isomorphism
isomorphism / Nim.hs
Created January 10, 2012 09:24
Code review
-- Suggested changes for http://codereview.stackexchange.com/q/7623/4949
module Nim where
import Data.List
import Data.Maybe
import qualified Data.Map as Map
--Domain
--Nim is a mathematical game of strategy
@isomorphism
isomorphism / 1.prof
Created January 2, 2012 02:00
profiling results
Sun Jan 1 20:57 2012 Time and Allocation Profiling Report (Final)
Main +RTS -sstderr -p -RTS
total time = 8.30 secs (415 ticks @ 20 ms)
total alloc = 519,870,364 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
calcRoots Main 74.7 38.7
@isomorphism
isomorphism / SetNFA.hs
Created December 19, 2011 06:30
quick NFA using a mock-monadic fold with Set instead of []
import Data.Set (Set)
import qualified Data.Set as S
bindSet :: (Ord a, Ord b) => Set a -> (a -> Set b) -> Set b
bindSet s k = S.unions . S.toList $ S.map k s
foldSet :: (Ord a ) => (a -> b -> Set a) -> a -> [b] -> Set a
foldSet _ a [] = S.singleton a
foldSet f a (x:xs) = bindSet (f a x) (\fax -> foldSet f fax xs)
module Main where
import Control.Monad.State
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
import Data.List (isPrefixOf, intercalate)
import Data.Char (toLower)
@isomorphism
isomorphism / StreamProc.hs
Created August 14, 2011 20:30
An example of a non-trivial Arrow, for cdsmith
{-# LANGUAGE TypeOperators #-}
module StreamProc where
import Prelude hiding ((.), id, const)
import Control.Category
import Control.Arrow
import Control.Applicative
const :: (Arrow (~>)) => a -> (b ~> a)
const x = arr (\_ -> x)
@isomorphism
isomorphism / RotateArgs.hs
Created July 16, 2011 18:25
generalized flip
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module RotateArgs where
data Z = Z
data S n = S n
class RotateArgs n a where
@isomorphism
isomorphism / output.txt
Created September 25, 2015 04:12
parsing with annotated hex dump
----------------------------------------------------------------------
vertex group
0x00004394 - 0x000043c3
0x4394 flags: 1073741826
0x4398 (16 bytes skipped):
0x43a8 vertex array bytes array, # entries: 135800
0x43ac vertex array bytes array offset: 0x47178
0x43b0 (8 bytes skipped):
0x43b8 vertex array stride bytes: 40
import Prelude hiding ((++), concat)
import Control.Applicative
import Control.Monad
import Data.Maybe
import Data.Monoid
import System.Random
import qualified Data.IntMap as IM
import Graphics.DrawingCombinators
import qualified Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Keysym