Skip to content

Instantly share code, notes, and snippets.

View vertexcite's full-sized avatar

Randall Britten vertexcite

  • Auckland, New Zealand
View GitHub Profile
@vertexcite
vertexcite / FtpFree.hs
Created October 22, 2015 10:58
Simpler `length`, `sum`, `product` for GHC 7.10 for beginners.
-- Something like this when teaching using GHC
-- so that beginners don't get confused by FTP versions
-- of length, sum, product, etc.
-- Usage: in ghci, `:l FtpFree.hs`
module FtpFree (length, sum, product) where
import Prelude hiding (length, sum, product)
length :: [a] -> Int
@vertexcite
vertexcite / AAA.txt
Last active August 29, 2015 14:21 — forked from Porges/AAA.txt
Using cabal to install quickcheck:
Make a directory to work in.
Inside the directory: “cabal sandbox init”
Then: “cabal install quickcheck”
You can open the GHCI repl in the sandbox:
"cabal repl"
And use normal commands like ":load filename.hs"
@vertexcite
vertexcite / eval.hs
Created April 28, 2015 05:26
Monad example: simple expression evaluation - for Auckland FP Meetup 2015-04-28. By Steve Reeves
---Very simple evaluation for arithmetic expressions with only constants
---(and only "plus"...obviously extendable to other operations)
data Expr = C Float |
Expr :+ Expr
deriving Show
eval :: Expr -> Float
eval (C x) = x
eval (e1 :+ e2) = let v1 = eval e1
@vertexcite
vertexcite / FunkyList.hs
Last active September 12, 2015 05:08
Monad instance of list where list is treated as a function (Nat -> Nat)
module FunkyList where
import Control.Monad
instance Functor FunkyList where
fmap = liftM
instance Applicative FunkyList where
pure = return
(<*>) = ap
@vertexcite
vertexcite / NumFunction.hs
Last active August 29, 2015 14:16
Num instance functions: Num a => Num (a -> a)
{-# LANGUAGE FlexibleInstances #-}
module NumFunction where
instance Num a => Num (a -> a) where
(f + g) x = f x + g x
(f * g) x = f x * g x
abs f = abs . f
signum f = signum . f
fromInteger x = const (fromInteger x)
negate f = negate . f
@vertexcite
vertexcite / Life.hs
Last active November 14, 2017 05:53
Conway's Game of Life and QuickCheck property based testing. Based on session with Stephen Blackheath at Global Day of Code Retreat, 15 November 2014. (Some minor tweaks since then.)
module Life where
import Data.Set (Set)
import qualified Data.Set as S
import Data.Foldable (foldMap)
type Cell = (Int, Int)
type World = Set Cell
@vertexcite
vertexcite / HeterogeneousList.hs
Last active August 29, 2015 14:08
Heterogeneous List in Haskell (simple version)
{-# LANGUAGE ExistentialQuantification #-}
-- This is adapted from http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types
-- See also https://www.haskell.org/haskellwiki/Heterogenous_collections#Existential_types
module HeterogeneousList where
data ShowBox = forall s. Show s => SB s
heteroList :: [ShowBox]
module Game2048 where
import Graphics.Collage as Collage
import Keyboard
import Random
import Transform2D as TF
import List exposing (..)
import Color exposing (rgb, green, black, grey)
import Graphics.Element exposing (show, color, centered, Element)
import Graphics.Collage exposing (Form)