Skip to content

Instantly share code, notes, and snippets.

@andrewthad
andrewthad / examples.hs
Created June 14, 2023 18:52
Examples of folds and strict folds
{-# language BangPatterns #-}
main :: IO ()
main = print (createMap myList)
myList :: [String]
myList = ["foo","bar","foo","bar"]
-- updateMap :: Map String Int -> String -> Map String Int
-- updateMap v k = Map.updateWith (+1) k m
@andrewthad
andrewthad / case-on-bytes.md
Created August 5, 2020 14:15
Case on Bytes without compiler support

This is an idea for how to case on a byte sequence without any special support from the compiler. The basic idea is explored in https://github.com/layer-3-communications/fortios-syslog, but there code generation is used rather than TemplateHaskell. The idea is that, at compile time, generating a perfect hash function for all strings of the same length is a good way to pattern match on a sequence of bytes. Roughly, we have:

foo :: Bytes -> Bar
foo b = case B.length b of
  3 -> case hash3 b of

Car | b == "car" -> ...

@andrewthad
andrewthad / T5030.boxedrep.prof
Created May 24, 2020 00:01
T5030 SCC Profiling for BoxedRep
Sat May 23 19:57 2020 Time and Allocation Profiling Report (Final)
ghc +RTS -p -RTS -B/home/amartin/ghc-boxedrep-prof/lib/ghc-8.11.0.20200518 ./testsuite/tests/perf/compiler/T5030.hs
total time = 0.56 secs (558 ticks @ 1000 us, 1 processor)
total alloc = 711,938,744 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
simplCast-simplCoercion GHC.Core.Opt.Simplify compiler/GHC/Core/Opt/Simplify.hs:1293:57-77 28.5 30.5
@andrewthad
andrewthad / boxedrep.txt
Created May 18, 2020 11:15
T5030 built with ticky compiler before and after boxed rep
This file has been truncated, but you can view the full file.
'/home/amartin/ghc-boxedrep-ticky/lib/ghc-8.11.0.20200515/bin/ghc' '-B/home/amartin/ghc-boxedrep-ticky/lib/ghc-8.11.0.20200515' '-O2' './testsuite/tests/perf/compiler/T5030.hs' +RTS '-rboxedrep.ticky'
STACK USAGE:
ENTERS: 124184476 of which 124184476 (100.0%) direct to the entry code
[the rest indirected via Node's info ptr]
19582791 ( 15.8%) thunks
21067039 ( 17.0%) data values
0 ( 0.0%) normal indirections
0 ( 0.0%) permanent indirections
@andrewthad
andrewthad / T9020-ghc-882.dump.txt
Created February 24, 2020 19:01
Typechecker dump for T9020 in GHC 8.8.2 and in GHC-boxedrep
checkFamInstConsistency [Prelude]
Tc2 (src)
Tc3
tcExtendKindEnvList []
tcExtendKindEnvList []
tcDeriving False
tcDeriving 1 []
rnd
Adding instances:
Tc3b
@andrewthad
andrewthad / base64_benchmarks.txt
Created January 16, 2020 11:55
Base64 Benchmark Suite
benchmarked encode/base64-bytestring/25
time 161.7 ns (152.6 ns .. 168.1 ns)
0.980 R² (0.944 R² .. 0.998 R²)
mean 178.6 ns (169.1 ns .. 216.5 ns)
std dev 55.41 ns (14.38 ns .. 113.1 ns)
variance introduced by outliers: 95% (severely inflated)
benchmarked encode/base64-bytestring/100
time 232.1 ns (228.7 ns .. 234.8 ns)
0.999 R² (0.998 R² .. 0.999 R²)
@andrewthad
andrewthad / questions.md
Created December 12, 2019 14:48
Questions

Haskell Questions

What are the benefits of a type system? Describe a problem that strong static typing helps prevent. Describe a problem that strong static typing does not help prevent.

What is recursion? What is well-founded recursion? What is a base case?

Define referential transparency. Why is this a desirable property of a function? What optimizations opportunities does it make possible?

@andrewthad
andrewthad / witherable_fusion_example.dump-simpl
Created December 12, 2019 13:36
Witherable List Fusion Consumer
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 444, types: 513, coercions: 11, joins: 0/4}
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
$trModule4 = "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
@andrewthad
andrewthad / ten_literals.hs
Created November 14, 2019 19:35
Ten ByteString Literals
{-# language OverloadedStrings #-}
{-# OPTIONS_GHC -O2 -fforce-recomp -ddump-simpl -dsuppress-all -ddump-to-file -ddump-cmm -ddump-asm #-}
module ConstantLength
( stringOne
, stringTwo
, stringThree
, stringFour
, stringFive
, stringSix
@andrewthad
andrewthad / ecs_records.hs
Created October 7, 2019 14:43
ECS Records
module Record where
-- This approach gives us everything we want except for a type-safe
-- way to project out subsets of columns. For these kinds of projections,
-- the user will need to manually project out each column, upcast them
-- to uncompressed arrays (if they aren't absent), logical AND any mask
-- vectors, and then pick the valid rows from the columns. This is
-- inconvenient, but this kind of projection is a niche use that currently
-- only happens in insight.