Skip to content

Instantly share code, notes, and snippets.

View tibbe's full-sized avatar

Johan Tibell tibbe

View GitHub Profile
test :: [Int] -> [Int]
test xs = filter (\x -> x `mod` 2 == 0) xs
test :: [Int] -> [Int]
test [] = []
test (x:xs)
| x `mod` 2 == 0 = x : test xs
| otherwise = test xs
{-# INLINE filter #-}
even :: Int -> Bool
even x = x `mod` 2 == 0
test :: [Int] -> [Int]
test xs = filter even xs
test :: [Int] -> [Int]
test [] = []
test (x:xs)
| even x = x : test xs
| otherwise = test xs
@tibbe
tibbe / gist:927099
Created April 19, 2011 10:27
copyArray# benchmark
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Main (main) where
import Data.Time.Clock
import GHC.Exts
import GHC.IO
import GHC.Prim
import GHC.ST
bench = stToIO $ ST $ \ s ->
@tibbe
tibbe / cmm.el
Created March 9, 2012 21:32
Cmm major mode that doesn't work
(defvar cmm-mode-hook nil)
(add-to-list 'auto-mode-alist '("\\.cmm\\'" . cmm-mode))
(defvar cmm-keywords
'("aborts" "align" "aligned" "also" "as" "big" "bits" "byteorder" "case"
"const," "continuation" "cut" "cuts" "else" "equal" "export" "foreign"
"goto" "if" "import" "in," "invariant" "invisible" "jump" "little" "memsize"
"pragma" "reads" "register," "return" "returns" "section" "semi" "span"
"stackdata" "switch" "target" "targets" "to," "typedef" "unicode" "unwinds"
@tibbe
tibbe / gist:4106836
Created November 18, 2012 18:55
Core output for Gaussian.hs
Rec {
$fUniformGaussianValuesDoubleDouble_ziggurat
:: forall g_a2D9.
RandomGen g_a2D9 =>
(Vector Double, Vector Double, Vector Word)
-> g_a2D9 -> (Double, g_a2D9)
$fUniformGaussianValuesDoubleDouble_ziggurat =
\ (@ g_a2D9)
($dRandomGen_a2Da :: RandomGen g_a2D9)
(eta_B2 :: (Vector Double, Vector Double, Vector Word))
{-# LANGUAGE BangPatterns #-}
module Main
( main
) where
import Control.Applicative
import Control.Monad (mzero)
import qualified Data.Vector as V
import Data.Vector (Vector)
@tibbe
tibbe / Main.hs
Created April 5, 2013 17:54
Program that walks the HsSyn AST to create a list of all names and their source locations. Usage: 1. Place Main.hs and Test.hs in same directory. 2. Compile and run: ghc Main.hs ./Main
{-# LANGUAGE BangPatterns, PatternGuards #-}
module Main (main) where
import Control.Monad (forM_, unless)
import Prelude hiding (id, mod)
import System.Environment (getArgs)
import System.Exit (ExitCode(ExitFailure), exitWith)
import Bag
import Digraph (flattenSCCs)