Skip to content

Instantly share code, notes, and snippets.

@eatonphil
eatonphil / thread.ml
Last active April 7, 2018 01:15
Basic thread logic based on condition variables in Poly/ML
(*
* Tested in Poly/ML. To compile: `polyc thread.ml && ./a.out`
*
* Heavily influenced by: http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf
* Poly/ML Thread documentation here: http://www.polyml.org/documentation/Reference/Threads.html
* Poly/ML Thread implementation here: https://github.com/polyml/polyml/blob/master/basis/Thread.sml
*)
val done = ref false;
val m = Thread.Mutex.mutex();
@eatonphil
eatonphil / poly-build.ml
Last active January 24, 2016 06:03
Poly/ML specific build tool partially reimplementing the polyc bash script in SML.
(*
* Poly/ML specific build tool partially reimplementing the polyc bash script in SML.
* Additionally, this adds a means to include files needed in the main script.
* Usage:
* $ polyc -o poly-build poly-build.sml # bootstrap the tool
* $ ./poly-build poly-build.sml # compile itself
* $ mv a.out poly-build
* $ ./poly-build a.sml b.sml c.sml # where needs some fun/val from b.sml and c.sml
*)
#! /bin/sh
prefix=/usr/local
exec_prefix=${prefix}
BINDIR=${exec_prefix}/bin
LINK=cc
LIBDIR=${exec_prefix}/lib
LIBS="-lpthread -lm -lgcc_s -lgcc -L/usr/local/lib -lffi "
CFLAGS="-O2 -pipe -fstack-protector -fno-strict-aliasing"
# Extra options for Windows. config.status sets these conditionals to either "" or "#".
@eatonphil
eatonphil / getreq.sml
Created February 27, 2016 22:59
Example of HTTP GET request in SML
(*
* Tested on Poly/ML.
* Usage:
* $ polyc getreq.sml
* $ ./a.out
*)
exception E of string
fun request domain path =
structure File = Ponyo.Os.File
structure String = Ponyo.String
structure Format = Ponyo.Format
val f = PolyML.NameSpace.displayTypeExpression
val g = PolyML.globalNameSpace
fun parseModule (path: string) =
let
@eatonphil
eatonphil / Web-related
Last active March 14, 2016 02:32
Ponyo project ideas
structure StringMap = Map(String)
let
val stringMap = StringMap.empty
val stringMap = StringMap.insert stringMap "key" "value"
val stringMap = StringMap.insert stringMap "key1" "value1"
in
assertEquals (StringMap.get stringMap "key1") "value1"
end
CHICKEN
(c) 2008-2015, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.10.0 (rev b259631)
freebsd-unix-clang-x86-64 [ 64bit manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)
#;1> (use match)
Error: (import) during expansion of (import ...) - cannot import from undefined module: match
(provide 'sml-mode)
(defface sml-highlight-misc
'((t (:foreground "light blue")))
"SML misc highlighting"
:group 'basic-faces)
(defface sml-highlight-builtin
'((t (:foreground "dark magenta")))
"SML builtin highlighting"
@eatonphil
eatonphil / monad.ml
Created June 7, 2016 20:25
Monads in ocaml
module MaybeMonad = struct
type 'a t = None | Maybe of 'a
let return (a: 'a) : 'a t = Maybe a
let (>>=) (m: 'a t) (f: 'a -> 'b t) : 'b t = match m with
| None -> None
| Maybe a -> f a
let get (m: 'a t) (a: 'a) = match m with