Skip to content

Instantly share code, notes, and snippets.

@ramntry
ramntry / pretty_expr_again.ml
Last active August 29, 2015 13:58
Another example
(* master *)
type 'e expr = [
| `Var of string
| `Ctr of string * 'e list
]
type pure = pure expr
let string_of_expr string_of_e = function
@ramntry
ramntry / merge2.c
Created April 4, 2014 16:05
g-function with GC support example
Object merge2_(Object ctr, Object hda_, Object tla_) {
struct {
struct RootsBlock header;
Object gcall_cnd;
Object gcall_merge2;
Object gcall_merge2_1;
Object gcall_lss;
Object ctr_Cons;
Object ctr_Cons_1;
Object ctr_Cons_2;
@ramntry
ramntry / test.c
Created April 5, 2014 16:07
SLL Test
#include "module_prolog.c"
enum {
Cons_,
F_,
N_,
Nil_,
S_,
T_,
Z_,
#include "module_prolog.c"
enum {
S_,
Z_,
SllNumofCtrs = 2
};
char const *const constructor_names[] = {
"S",
Ребята, тут такая история.
У меня улучшился (я на это надеюсь) io.
И вот в каком смысле.
Из соображений производительности внутреннее представление конструкторов было выбрано таким:
+--------+------+------+-----+------+
| header | arg1 | arg2 | ... | argN |
+--------+------+------+-----+------+
где header имеет вид
#!/usr/bin/env python
text = raw_input().split(", Cons(C")
text = text[0].split("Cons(C")[1:] + text[1:-1] + text[-1].split(",")[0:1]
translated = []
for char in text:
if len(char) == 1:
translated.append(char)
else:
translated.append(chr(int(char[1:], 16)))
module Main where
data Tree a =
Empty
| Node (Tree a) a (Tree a)
treeFromList :: (Ord a) => [a] -> Tree a
treeFromList = foldl insert Empty
where
insert Empty x = Node Empty x Empty
CAMLC = ocamlopt.opt
INCLUDE = \
-I ../../src/sll
LIBS = \
sll.cmx \
arithm.cmx
CAMLC_FLAGS = \
@ramntry
ramntry / exceptions.cpp
Created May 9, 2014 15:06
C++ Exceptions microbenchmark
#include <iostream>
#include <sys/time.h>
double now() {
timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1.0e6 + tv.tv_usec;
}
void factorial_helper(long n) {
@ramntry
ramntry / exceptions.ml
Created May 9, 2014 16:01
OCaml Exceptions microbenchmark
exception Result of int
let factorial n =
let rec factorial_helper = function
| 0 -> raise (Result 1)
| n ->
try
factorial_helper (n - 1)
with Result prev -> raise (Result (prev * n))
in