Skip to content

Instantly share code, notes, and snippets.

View amosr's full-sized avatar

Amos Robinson amosr

View GitHub Profile
@amosr
amosr / gist:12b32e901fed6bb4431446b055d0dc0d
Created December 21, 2016 21:58
Make with nothing to do
# make with nothing to do still runs ghc 364 times.
# also, ghc 8 seems to take twice as long to do nothing than 7.10
amos@Amos ddc $ g
The Glorious Glasgow Haskell Compilation System, version 7.10.2
amos@Amos ddc $ time make
make[2]: Nothing to be done for `deps'.
make[2]: `bin/ddc-check' is up to date.
real 0m10.593s
@amosr
amosr / Test.hs
Created December 21, 2016 02:24
GHC dynamic bug maybe
module Test where
foo :: Int
foo = 1 + 2
@amosr
amosr / Map.dcm
Created December 8, 2016 03:29
Map combinator
module Map
export
map : [a b : Data]. (a -> b) -> Stream# a -> Stream# b
with letrec
unwrap [a : Data] (xx : Tuple1# a) : a = case xx of T1# a -> a
map [a b : Data] (f : a -> b) (as : Stream# a) : Stream# b
= unwrap (stream_1_1# (\inp out. letrec
p1 = pull# inp p2
@amosr
amosr / strymonas.ml
Created December 1, 2016 20:48
zip of partition
(* stream example that would require an unbounded buffer *)
(* read some ints from the network or something *)
(* assume this is infinite so can't buffer *)
let long_stream = unfold read_network socket
(* filter into two streams: those above and those below 0 *)
in let bigs = filter (fun x -> x > 0) long_stream
in let smalls = filter (fun x -> x < 0) long_stream
(* zip the two filtered streams together *)
in let join = zip bigs smalls
// Tree implementation using Box of Option of Node.
// Would hope Box<Option<Node>> should be just *Node where null = None
// But it appears to use ***Node as argument type in lookup
pub struct Node {
val: i64,
l: Tree,
r: Tree,
}
pub type Tree = Box<Option<Node>>;
@amosr
amosr / THStuff.hs
Created September 2, 2016 00:31
Template Haskell reify does not return declaration
-- Template haskell parts need to be in separate module, because of staging restriction.
-- Use GHC 8, since the VarI constructor changed between 7 and 8.
{-# LANGUAGE TemplateHaskell #-}
module THStuff where
import Language.Haskell.TH
-- Try to convert a name into its definition.
-- This would be really useful for forcing definitions to be inlined into a particular callsite.
get :: Name -> Q Exp
get nm = do
@amosr
amosr / lucy.sh
Last active May 24, 2016 08:17
Installing and running Lucid Synchrone (Lucy)
#!/bin/sh -eu
# The version of Lucid Synchrone / Lucy on the website was built a long time ago, and only has bytecode available.
# It seems that between ocaml 4.00.1 and 4.00.2, the bytecode format changed,
# so you need to use that version.
# This should:
# install the right version of the compiler (assuming you have opam);
# download lucy;
# change the shebang of the binaries to point to the right version;
# and put lucyc in /usr/local/bin.
@amosr
amosr / sums.c
Last active May 3, 2016 23:13
No global value numbering / duplicate removal
#include <stdio.h>
void b01_sums(int size, int* A)
{
int sum0 = 0;
int sum1 = 0;
for (int i = 0; i != size; ++i)
{
sum0 = sum0 + A[i];
sum1 = sum1 + A[i];
@amosr
amosr / bonkers.hs
Created April 1, 2016 01:01
Type families error that I don't understand
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
class Bonkers b where
type Bonkers1 b :: *
type Bonkers2 b :: *
bonkersFrom :: Bonkers1 b -> Bonkers2 b
bonkers' :: Bonkers b => Bonkers1 b -> Bonkers2 b
@amosr
amosr / fusion.md
Last active March 13, 2016 04:34
Icicle lambda jam abstract(s)

Icicle: write once, run once

When dealing large data sets that do not fit in memory, it is crucial to limit the number of accesses and iterations over the data set. However, in a high level language it may not be immediately obvious how many iterations a particular program will require. The number of iterations becomes even less obvious in the presence of heuristic and statistics-based optimisations, as used by traditional databases: a small tweak to the query or even modifying the number of rows in a table can cause drastic changes to the query plan.