Skip to content

Instantly share code, notes, and snippets.

View kfl's full-sized avatar
🤓
Happy

Ken Friis Larsen kfl

🤓
Happy
View GitHub Profile
@kfl
kfl / gadtexpr.hs
Created January 10, 2012 14:14
Classic example on how to use GADTs
{-# LANGUAGE GADTs #-}
data Expr t where
Con :: Int -> Expr Int
Add :: Expr Int -> Expr Int -> Expr Int
Mult :: Expr Int -> Expr Int -> Expr Int
IsZ :: Expr Int -> Expr Bool
If :: Expr Bool -> Expr t -> Expr t -> Expr t
And :: Expr Bool -> Expr Bool -> Expr Bool
Or :: Expr Bool -> Expr Bool -> Expr Bool
{-# LANGUAGE BangPatterns #-}
module Main (main) where
import System.Environment (getArgs)
import qualified Char
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL
@kfl
kfl / lengthbench.hs
Created August 19, 2010 07:22
Benchmarking of build-in length and custom length function using criterion
{-
Benchmarking of build-in length and custom length function using criterion.
Compile with the command: ghc -O3 -W --make lengthbench.hs -o lengthbench
Results (timings in seconds, std. dev. negligible):
build-in length:
1000000 0.004
2000000 0.009
4000000 0.016
@kfl
kfl / memexercise.sml
Created June 11, 2010 07:23
Exercise the garbage collector
fun genVec n = Vector.tabulate(n, fn i => i)
local val gen = Random.newgenseed 42.0 in
fun random_length () = Random.range(500, 200*16192) gen
fun range rng = let val f = Random.range rng in fn () => f gen end
end
fun initial n = List.tabulate(n, fn _ => genVec(random_length()))
fun split_at i lst =