This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Monads with camlspotter's ppx_typeclass *) | |
(* see ppx_typeclass http://bitbucket.org/camlspotter/ppx_typeclass/ *) | |
(* Set-up higher-kinded polymorphism, see https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf *) | |
type ('p, 'f) app = .. (* Type-level defunctionalization *) | |
module Newtype1 (T: sig type 'a t end) () = struct | |
type 'a s = 'a T.t | |
type t | |
type (_, _) app += App : 'a s -> ('a, t) app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* try at http://try.ocamlpro.com/js_of_ocaml/ *) | |
open Graphics | |
let () = open_graph " 900x600" | |
let rec k c = | |
clear_graph (); | |
moveto 450 300; | |
draw_string (string_of_int c); | |
ignore (Dom_html.window##setTimeout(Js.wrap_callback (fun _ -> k (c+1)), 0.1)) | |
let () = k 0 ;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xpath(elm, expr) { | |
var it = document.evaluate(expr, elm, null, XPathResult.ANY_TYPE, null); | |
var typ = it.resultType; | |
switch(typ) { | |
case XPathResult.NUMBER_TYPE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec fib n = | |
if n <= 1 then | |
1 | |
else | |
let x = fib (n-1) | |
and y = fib (n-2) | |
in x+y | |
let main n = print_int (fib n) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SMLYACC=smlyacc | |
SMLLEX=smllex | |
SMLSHARP=smlsharp | |
OBJS=calc.grm.o calc.lex.o calc.o | |
SMI=calc.grm.smi calc.lex.smi calc.smi | |
all: calc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check this with facebook infer 0.9.4 | |
public class Hello { | |
public static void main(String[] args) { | |
Object o1 = new Object(); | |
Object o2 = new Object(); | |
Object n = null; | |
Object[] arr = {o1, o1, o1, o1, o1}; | |
for(int i=0; i<arr.length; i++) { | |
if(arr[i].equals(o2)) { | |
n.equals(n); // never reached but reported as an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A monad in Crystal | |
class Id(T) | |
getter :value | |
def initialize(@value : T) | |
end | |
def bind(&x : T -> Id(U)) forall U | |
yield @value | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IxMonad<X,Y,T>(val x:T) {} | |
class Cons<HD,TL>(val hd : HD, val tl : TL) {} | |
class Nil(); | |
fun <X,Y,T> ret(x: T) : IxMonad<X,Y,T> { | |
return IxMonad<X,Y,T>(x) | |
} | |
fun <T> run(m : IxMonad<Nil,Nil,T>) : T { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
import java.util.ArrayList; | |
public class TypeError { | |
public static <A> void let(A a, Consumer<A> f) { | |
f.accept(a); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* try this with 4.02.0+modular-implicits *) | |
module type Show = sig | |
type t | |
val show : t -> string | |
end | |
implicit module Lam{X:Show} = struct | |
type t = [`Var of string | `App of X.t * X.t | `Abs of string * X.t] | |
let show : t -> string = function | |
|`Var(x) -> x |