Skip to content

Instantly share code, notes, and snippets.

View Leonidas-from-XIV's full-sized avatar

Marek Kubica Leonidas-from-XIV

View GitHub Profile
let split_by = Str.regexp ","
let read_line chan =
match input_line chan with
| c -> Some c
| exception End_of_file -> None
let rec fold_channel f acc chan =
match read_line chan with
| Some line -> fold_channel f (f line acc) chan
import qualified Data.Map as M
type State = String
type Symbol = (String, Int)
data TreeAutomaton = TreeAutomaton
{ symbols :: [Symbol]
, states :: [State]
, finalStates :: [State]
, delta :: M.Map (Symbol, [State]) State
@Leonidas-from-XIV
Leonidas-from-XIV / mastermind.ml
Created April 21, 2015 15:15
For caml in #ocaml
open Core_kernel.Std
type colour = Red | Green | Magenta | Yellow | Blue | Black | White | Cyan
let shuffle l =
List.map ~f:(fun c -> (Random.bits (), c)) l
|> List.sort ~cmp:compare
|> List.map ~f:snd
let all = [Red; Green; Magenta; Yellow; Blue; Black; White; Cyan]
module Safe = struct
module Util : sig
type t = Yojson.Safe.json
val member : string -> t -> t
end = struct
let rec find_key name = function
| [] -> None
@Leonidas-from-XIV
Leonidas-from-XIV / ti.ml
Created April 16, 2015 09:04
Timeouts in Lwt; build with ocamlbuild -pkgs lwt.unix ti.native
let () =
let sleep, wake = Lwt.wait () in
let ti = Lwt_timeout.create 2 (fun () ->
print_endline "oh hai";
Lwt.wakeup_later wake ()) in
Lwt_timeout.start ti;
Lwt_main.run sleep
@Leonidas-from-XIV
Leonidas-from-XIV / typeerror.txt
Created January 12, 2015 20:47
Error messages I am producing
File "src/slacko.ml", line 1:
Error: The implementation src/slacko.ml
does not match the interface src/slacko.cmi:
Values do not match:
val groups_rename :
string ->
group ->
string ->
[> `Account_inactive
| `Channel_not_found
@Leonidas-from-XIV
Leonidas-from-XIV / backtrace
Created December 5, 2014 15:21
ctypes/LLVM issue
Program received signal SIGSEGV, Segmentation fault.
do_lookup_x (undef_name=undef_name@entry=0x4037c2 "__deregister_frame", new_hash=new_hash@entry=2068692891,
old_hash=old_hash@entry=0x7fffffffda00, ref=0x4022a0, result=result@entry=0x7fffffffda10, scope=0x7fff00000000, i=0,
version=0x7ffff7fd98d0, flags=1, skip=0x0, type_class=1, undef_map=0x7ffff7ffe148) at dl-lookup.c:353
353 size_t n = scope->r_nlist;
(gdb) bt
#0 do_lookup_x (undef_name=undef_name@entry=0x4037c2 "__deregister_frame", new_hash=new_hash@entry=2068692891,
old_hash=old_hash@entry=0x7fffffffda00, ref=0x4022a0, result=result@entry=0x7fffffffda10, scope=0x7fff00000000, i=0,
version=0x7ffff7fd98d0, flags=1, skip=0x0, type_class=1, undef_map=0x7ffff7ffe148) at dl-lookup.c:353
#1 0x00007ffff7de57e8 in _dl_lookup_symbol_x (undef_name=0x4037c2 "__deregister_frame", undef_map=0x7ffff7ffe148, ref=0x7fffffffdac8,
ocamlfind c -I /home/marek/llvm36/lib/ocaml -cclib -L/home/marek/lib -cc g++ -ccopt -Wno-write-strings llvm_target.cma llvm_executionengine.cma -safe-string -warn-error +a -g -I src/global -I src/scanparse -I src/simplify -I src/typecheck -I src/normalize -I src/optimize -I src/codegen -package menhirLib -package ctypes.foreign -bin-annot unix.cma str.cma menhirLib.cmo llvm.cma llvm_bitreader.cma llvm_bitwriter.cma -o bin/stellarunit src/stellarunit.cmo
File "_none_", line 1:
Error: Error while linking /home/marek/llvm36/lib/ocaml/llvm_executionengine.cma(Llvm_executionengine):
Reference to undefined global `Ctypes'
@Leonidas-from-XIV
Leonidas-from-XIV / typeloss.ml
Created December 2, 2014 22:43
Losing type information via flip
let query uri return_value_fn =
let%lwt (_, body) = Cohttp_unix.Client.get uri in
let%lwt content = Cohttp_body.to_string body in
Yojson.Basic.from_string content
|> validate
|> filter_useless
|> return_value_fn
|> Lwt.return
let flip f x y = f y x
module type I = sig
type t
val id: t -> t
end
module Integers = struct
type t = int
let id x = x
end