Skip to content

Instantly share code, notes, and snippets.

View doublec's full-sized avatar

Chris doublec

  • Perth, Australia
View GitHub Profile
staload "libc/SATS/signal.sats"
staload "libc/SATS/stdio.sats"
staload "libc/SATS/unistd.sats"
staload "libc/sys/SATS/wait.sats"
staload "libc/sys/SATS/types.sats"
staload "libc/sys/SATS/socket.sats"
staload "libc/netinet/SATS/in.sats"
staload "libc/arpa/SATS/inet.sats"
staload "prelude/DATS/array0.dats"
staload "libc/SATS/random.sats"
staload "libc/SATS/unistd.sats"
staload "libats/SATS/parworkshop.sats"
staload "libats/DATS/parworkshop.dats"
staload "prelude/DATS/array.dats"
#define ITER 100000000
#define NCPU 2
fn random_double (buf: &drand48_data): double = let
staload "libc/SATS/random.sats"
staload "libc/SATS/unistd.sats"
staload "libats/SATS/parworkshop.sats"
staload "libats/DATS/parworkshop.dats"
staload "prelude/DATS/array.dats"
#define ITER 100000000
#define NCPU 2
fn random_double (buf: &drand48_data): double = let
@doublec
doublec / namecoin-hosts.c
Created May 12, 2011 05:27
namecoin-hosts
/*
Copyright (c) 2011, Chris Double
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@doublec
doublec / test.dats
Created October 30, 2011 23:47
Structures and linear resources
%{^
typedef struct resource {
void* data;
int x;
} resource;
%}
absviewtype data_vt (l:addr)
extern fun data_vt_make (): [l:agz] (data_vt l ) = "mac#data_make"
extern fun data_vt_free {l:addr} (r: data_vt l): void = "mac#data_free"
fun foo {v:view} (pf: !v | b1: (!v | int) -<cloref> void):void = {
val v = 5
val () = b1(pf | v)
}
implement main () = {
var x: int? with pf_x
viewdef V = int? @ x
val () = foo {V} (pf_x | lam (pf | newval) => x := newval)
val () = printf("%d\n", @(x))
staload "contrib/task/SATS/task.sats"
dynload "contrib/task/DATS/task.dats"
fn do_main (sch: scheduler) = begin
set_global_scheduler (sch);
task_spawn (16384, lam () => begin
print ("hello\n");
task_yield ();
print ("world\n")
@doublec
doublec / Makefile
Created August 30, 2012 04:23
ATS FFI example
all: base64
base64: base64.dats
atscc -o base64 base64.dats
@doublec
doublec / Makefile
Created October 3, 2012 11:26
ATS stack example
all: stack1 stack2 stack3 stack4 stack5
stack1: stack1.dats
atscc -o stack1 stack1.dats
stack2: stack2.dats
atscc -o stack2 stack2.dats
stack3: stack3.dats
atscc -tc stack3.dats
@doublec
doublec / gist:6171436
Created August 7, 2013 05:24
ATS factorial with proof
/* From an example in the ATS distribution */
dataprop FACT (int, int) =
| FACTzero (0, 1)
| {n,r,r1:int | n > 0} FACTsucc (n, r) of (FACT (n-1, r1), MUL (n, r1, r))
fun fact {n:nat} .<n>. (n: int n): [r:int] (FACT (n, r) | int r) =
if n > 0 then let
val (pf1 | r1) = fact (n - 1)
val (pf_mul | r) = n imul2 r1
in