Skip to content

Instantly share code, notes, and snippets.

View kayceesrk's full-sized avatar

KC Sivaramakrishnan kayceesrk

View GitHub Profile
(* deep_state.ml *)
open Effect
open Effect.Shallow
module type State = sig
type a
type _ Effect.t += Get : a Effect.t
type _ Effect.t += Set : a -> unit Effect.t
end
@kayceesrk
kayceesrk / ocaml-native.md
Last active March 28, 2023 06:19
OCaml native code notes

Concurrency primitives

Signature

(* raw continuation *)
type ('a,'b) stack
perform  : 'a eff -> 'a
resume   : ('a,'b) stack -> ('c -> 'a) -> 'c -> 'b
delegate : 'a eff -> ('a,'b) stack -> 'b
(* The Computer Language Benchmarks Game
* https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
*
* Contributed by Troestler Christophe
* Modified by Fabrice Le Fessant
* *reset*
*)
type 'a tree = Empty | Node of 'a tree * 'a * 'a tree
type tree = Leaf of int | Node of tree * tree
let gensym = ref 0
let rec build_tree n =
if n <= 0
then (incr gensym; Leaf !gensym)
else Node(build_tree (n-1), build_tree (n-1))
let test n repet =
open Printf
open EffectHandlers
open EffectHandlers.Deep
module type STATE = sig
type t
val put : t -> unit
val get : unit -> t
val run : (unit -> 'a) -> init:t -> t * 'a
end
effect E : unit
let foo () =
let r = Atomic.make 0 in
perform E;
Atomic.set r (Atomic.get r + 1);
Atomic.get r
let bar () =
let r = ref 0 in
# Prints the slots available in Chennai for 18+ vaccination for the next 2
# weeks.
#
# Chennai's district id is 571.
# See https://apisetu.gov.in/public/marketplace/api/cowin#/Metadata%20APIs
import datetime
import requests
import json
let n = try int_of_string (Sys.argv.(1)) with _ -> 25
module MkGen (S :sig
type 'a t
val iter : ('a -> unit) -> 'a t -> unit
end) : sig
val gen : 'a S.t -> (unit -> 'a option)
end = struct
let gen : type a. a S.t -> (unit -> a option) = fun l ->
let module M = struct effect Yield : a -> unit end in
## Docker file for OCaml with GDB support
#
# Build
# -----
# $ mkdir monda-docker
# $ cp <this_file> monda-docker/
# $ docker build --force-rm=true -t monda .
# ..takes a while..
#
# Run
@kayceesrk
kayceesrk / stlc.prolog
Last active November 22, 2019 14:05
Type inference and program synthesis from simply typed lambda calculus type checking rules
?- set_prolog_flag(occurs_check,true).
lookup([(X,A)|_],X,A).
lookup([(Y,_)|T],X,A) :- \+ X = Y, lookup(T,X,A).
/* Rules from the STLC lecture */
pred(D,DD) :- D >= 0, DD is D - 1.
type(_,u,unit,D) :- pred(D,_).