Skip to content

Instantly share code, notes, and snippets.

View ndmitchell's full-sized avatar

Neil Mitchell ndmitchell

View GitHub Profile
@ndmitchell
ndmitchell / hlint.profiterole.txt
Created June 2, 2017 20:54
hlint.profiterole.txt
TOT INH IND
51.0 47.4 - Hint.Match readMatch (53)
12.0 12.0 - Data.Generics.Uniplate.Internal.Data readCacheFollower (3)
10.3 10.2 .6 Language.Haskell.Exts parseFileContentsWithComments (53)
8.7 7.5 7.5 Data.Generics.Uniplate.Internal.Data uniplateData (1377837)
99.9 5.2 - MAIN MAIN (0)
2.9 2.8 2.0 Data.Generics.Uniplate.Internal.Data descendBiData (109203)
2.4 2.4 - HSE.All runCpp (53)
2.3 2.3 2.3 Data.Generics.Uniplate.Internal.Data typeKey (2721430)
1.9 1.5 1.5 Data.Generics.Uniplate.Internal.Data fromOracle (1031785)
@ndmitchell
ndmitchell / hlint.prof
Created June 2, 2017 20:53
HLint profile
This file has been truncated, but you can view the full file.
Thu Jun 01 08:33 2017 Time and Allocation Profiling Report (Final)
hlint +RTS -P -RTS src
total time = 1.24 secs (1242 ticks @ 1000 us, 1 processor)
total alloc = 2,511,288,344 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc ticks bytes
@ndmitchell
ndmitchell / DList.hs
Created April 23, 2017 19:52
DList benchmarks
{-# OPTIONS_GHC -O2 #-}
import Control.Monad
import Control.Exception
import System.Time.Extra
import Criterion.Main
type DList a = [a] -> [a]
dTo f = f []
@ndmitchell
ndmitchell / hlint.prof
Created January 24, 2017 21:51
Example of a profile report that displays badly in Profiteur
Tue Jan 24 08:33 2017 Time and Allocation Profiling Report (Final)
hlint +RTS -p -RTS src
total time = 2.27 secs (2274 ticks @ 1000 us, 1 processor)
total alloc = 42,443,280,112 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
uniplateData Data.Generics.Uniplate.Internal.Data 41.4 68.1

Haskell can be written using nothing more than a text editor, and most popular editors include Haskell syntax highlighting out of the box. In addition, some editors can be enhanced to provide IDE-like features, using the tools listed below.

Intero (Emacs enhancement)

  • Provides instant error feedback, completions, go to definition, applying suggestions, type of expression.
  • Works with GHC 7.8 onwards, benefits from Stack.
{-# LANGUAGE Rank2Types #-}
import qualified Core.IO as F
import qualified Core.String as F
import qualified Core.Array as F
import qualified Core.VFS as F
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString as BS
import Codec.Compression.GZip as GZip
import Codec.Archive.Tar as Tar
Each key gets intern'd into an Id
Key :-> Id
Id :-> Status
@ndmitchell
ndmitchell / Rethinking.md
Created July 2, 2016 19:56
Shake - rethinking rules

I suspect the below isn't a good idea, because the remember needs repeating lots of times for every user of a rule. The new design seems to eliminate these issues more cleanly, but it's an interesting point in the design space.

Rethinking Rules

The current Rule typeclass has a number of issues. It's a bit complex to use, it often results in more dependencies than you were hoping, it's hard to control. People often end up defining oracles instead or rules but then you don't get options for other things. This document attempts to rethink that.

Concept

Shake runs rules that produce values. These rules track the current state of the system (other rules) and external values (files on disk). Currently the value produced by a rule is tracked automatically. This is often awkward. Imagine we want:

stack setup
stack install happy alex
stack exec -- pacman -S gcc binutils git automake-wrapper tar make patch --no-confirm
stack exec -- git clone --recursive git://git.haskell.org/ghc.git
cd ghc
stack exec -- git clone git://github.com/snowleopard/shaking-up-ghc shake-build
stack exec -- perl boot
stack exec -- bash configure --enable-tarballs-autodownload
stack build --stack-yaml=shake-build/stack.yaml --only-dependencies
stack exec --stack-yaml=shake-build/stack.yaml -- shake-build/build.bat -j
@ndmitchell
ndmitchell / GCHQ.hs
Created December 21, 2015 20:59
GCHQ 2015 Puzzle in Haskell
module Main(main) where
import Data.Maybe
import Data.List
-- Data table copied from https://matthewearl.github.io/2015/12/10/gchq-xmas-card/
width = 25
height = 25
rows = [