Skip to content

Instantly share code, notes, and snippets.

View takahisa's full-sized avatar

Takahisa Watanabe takahisa

  • Cybozu, Inc
  • Tokyo, Japan
View GitHub Profile
#/bin/bash
OCAML_DIRECTORY=${HOME}/.opt/ocaml/ocaml-4.04.2/
OCAML_BYTERUN=${OCAML_DIRECTORY}/byterun/ocamlrun
OCAML_DUMPOBJ=${OCAML_DIRECTORY}/tools/dumpobj
if [ $# != 2 ]; then
echo "usage: $0 <input> <output>" 1>&2
exit 0
fi
#/bin/bash
OCAML_DIRECTORY=${HOME}/.opt/ocaml/ocaml-4.04.2/
OCAML_BYTERUN=${OCAML_DIRECTORY}/byterun/ocamlrun
OCAML_DUMPOBJ=${OCAML_DIRECTORY}/tools/dumpobj
if [ $# != 2 ]; then
echo "usage: $0 <input> <output>" 1>&2
exit 0
fi
@takahisa
takahisa / open_recursion.ml
Created August 7, 2017 01:36
open-recursion
module Eval_base = struct
let eval eval_rec = function
| `Int n -> n
| _ ->
failwith "unknown expression"
let show show_rec = function
| `Int n -> string_of_int n
| _ ->
failwith "unknown expression"
@takahisa
takahisa / f-bound-type-encoding.cs
Created August 2, 2017 04:11
Generics (F-bound type) approach
namespace ExpressionProblem {
using System;
interface Exp<E> where E: Exp<E> { }
class Int<E>: Exp<E> where E: Exp<E> {
public int Value { get; set; }
}
class Add<E>: Exp<E> where E: Exp<E> {
public E Operand0 { get; set; }
@takahisa
takahisa / tagless-final-style.ml
Created July 31, 2017 02:49
Extensible Interpreter/Tagless Final Approach
module type SYM_base = sig
type 'a repr
val lam: ('a repr -> 'b repr) -> ('a -> 'b) repr
val app: ('a -> 'b) repr -> 'a repr -> 'b repr
end
module type SYM_bool = sig
include SYM_base
val bool: bool -> bool repr
val not_: bool repr -> bool repr
(*
* Copyright (c) 2017 Takahisa Watanabe <[email protected]> All rights reserved.
*
* 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:
*
(*
* Copyright (c) 2017 Takahisa Watanabe <[email protected]> All rights reserved.
*
* 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:
*
@takahisa
takahisa / gist:755638333a0fd334819bd8c7d3f4a9a9
Created May 18, 2017 08:39
Extensible VariantsとClassによるOpen-Recursionを用いた拡張可能なインタプリタ
(*
* Extensible VariantsとClassによるOpen-Recursionを用いた拡張可能なインタプリタ
* [author] linerlock
* [update] 2017/05/18
*)
module type SYNTAX = sig
type var
type tpe = ..
type exp = ..
@takahisa
takahisa / one-liner.sh
Created January 22, 2017 14:31
Batch Indentation with Emacs
find . -name "*.ml" -exec emacs --batch {} --eval '(progn (indent-region (point-min) (point-max) nil) (save-buffer))' \;
@takahisa
takahisa / syb2.ml
Created January 17, 2017 00:24
Scrap_Your_Boilerplate_2
type (_, _) eql = Refl : ('a, 'a) eql
type _ type_rep = ..
module type TYPEABLE =
sig
type t
val type_rep : unit -> t type_rep
val eqty : 's type_rep -> (t, 's) eql option
end