Skip to content

Instantly share code, notes, and snippets.

@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.
@andrewthad
andrewthad / block_leak.hs
Created July 22, 2019 19:12
GHC Block Leak
{-# language BangPatterns #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}
{-# OPTIONS_GHC -O2 -Wall -fforce-recomp #-}
import GHC.Exts
import GHC.IO (IO(..))
import System.Mem (performMajorGC)
@andrewthad
andrewthad / ascending_unsigned.c
Created July 16, 2019 12:15
Read or write 64-bit unsigned words from or to file
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <inttypes.h>
int main () {
FILE *file = NULL;
uint64_t buffer[1]; // array of bytes, not pointers-to-bytes
size_t bytesRead = 0;
@andrewthad
andrewthad / ProducerRequest.core.txt
Created July 11, 2019 16:04
ProducerRequest GHC Core
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 1,859, types: 3,380, coercions: 2,902, joins: 12/46}
-- RHS size: {terms: 22, types: 60, coercions: 32, joins: 0/0}
produceRequest1
produceRequest1
= \ s1_asVO ->
@andrewthad
andrewthad / stack_trace_primitive.hs
Created July 1, 2019 19:58
Playing with Stack Traces when indexing into byte arrays
{-# language BangPatterns #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}
import GHC.Exts
import GHC.IO (IO(..))
import Control.Exception (SomeException,toException)
import System.IO.Error (userError)
main :: IO ()
@andrewthad
andrewthad / T16391.trace.txt
Created June 12, 2019 12:33
T16391 Typechecker Trace
[1 of 1] Compiling T16391a ( T16391a.hs, T16391a.o )
checkFamInstConsistency [Data.Kind, Prelude]
Tc2 (src)
Tc3
tcExtendKindEnvList []
tcExtendKindEnvList []
---- tcTyClGroup ---- {
Decls for [Const]
tcExtendKindEnv [rs4 :-> APromotionErr TyConPE]
---- kcTyClGroup ---- {
@andrewthad
andrewthad / notes_to_self.txt
Created May 31, 2019 13:38
Notes to self about pipes, stdout, and a faster logger
I'd like to write a library kind of like sockets except that it would be used for dealing with named/unnamed unix pipes instead. The interface would be really similar. One big question is "how does the whole blocking/nonblocking thing work"? It doesn't work at all for regular files in linux but it works great for sockets. If you hook a pipe (like stdin or stdout) up to a file descriptor, does it always show it being ready, or does it work correctly? Pipes provide some kind of buffering, so maybe it works, but maybe it doesn't. I don't know. On linux, libuv always uses blocking IO when dealing with stdout. This is documented at http://nodejs.org/dist/v0.10.26/docs/api/process.html#process_process_stdout, but I do not understand why it was done. The IO manager that GHC ships with base requires some weirdness to get file descriptors to work nicely. It sometimes uses blocking IO and sometimes nonblocking IO depending on the threaded/nonthreaded runtime and on whether or not the file descriptor was created by the