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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test where | |
foo :: Int | |
foo = 1 + 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |