Skip to content

Instantly share code, notes, and snippets.

@petermarks
petermarks / gist:702671
Created November 16, 2010 22:45
Expression parser
import Data.Maybe
import Text.Printf
import Data.Char
import Control.Monad
data Expr = Term Int | Op Operator Expr Expr | Var String
deriving (Show, Eq)
data Operator = Sum | Mult | Sub | Div
deriving (Show, Eq)
@petermarks
petermarks / expressions.hs
Created September 20, 2010 21:05
Simple arithmetic expression language
module Expressions where
import Data.Maybe
import Text.Printf
import Control.Applicative
data Expr = Term Int | Op Operator Expr Expr | Var String
deriving (Show, Eq)
data Operator = Sum | Mult | Sub | Div
@petermarks
petermarks / guesser.hs
Created September 20, 2010 20:59
Number guesser iterations
module Main where
import Data.Char
import Data.List
data Guess
= Guess Int Guess Guess
| GiveUp
| Done
@petermarks
petermarks / guessMaker.hs
Created September 20, 2010 20:46
Number guesser
module Main where
makeAGuess :: Int -> Int -> Int
makeAGuess i j = (i + j) `div` 2
guess :: Int -> Int -> IO ()
guess i j = do
let x = makeAGuess i j
putStrLn (show x)
@petermarks
petermarks / Rope Intranet benchmark
Created September 5, 2010 21:02
Benchmark of Rope Intranet counting function
-- | This program benchmarks different versions of the counting function for
-- the Rope Intranet problem for Google Code Jam
-- http://code.google.com/codejam/contest/dashboard?c=619102#.
--
-- To compile:
-- >>> ghc -O2 --make bench.hs
--
-- To run (Windows):
-- >>> Bench
@petermarks
petermarks / GuessGame-abstracted.hs
Created August 22, 2010 22:21
Number guessing game
module Main where
import System.Random
import Data.Function
processGuess :: Int -> IO () -> IO ()
processGuess answer cont = do
n <- getLine
case compare (read n) answer of
EQ -> putStrLn "Awesome!!!!"
@petermarks
petermarks / gist:510622
Created August 6, 2010 00:19
Notes for Johan Lindberg
In http://github.com/johanlindberg/langgeeks/commit/3e6249fcd36be6685cce2a6936da8dd2471cbd51
you have:
> process :: String -> (Char, [String])
> process filename = do contents <- readFile filename
> return (getPlayer contents, getBoard contents)
It looks like you want to read the file and extract the player and board to pass this on to
another function. All that is missing here is the IO in the type signature.