Skip to content

Instantly share code, notes, and snippets.

View leque's full-sized avatar

OOHASHI Daichi leque

View GitHub Profile
module With_position = struct
type 'a t =
{ value : 'a
; pos : Lexing.position
}
end
type 'dict atom =
[ `Symbol of string
| `Vector of 't array
@leque
leque / o.ml
Created December 25, 2020 02:00
optics subtyping via phantom type + class type
class type a_setter = object
method setter : unit
end
class type a_getter = object
method getter : unit
end
class type a_lens = object
inherit a_getter
@leque
leque / optic.ml
Last active December 22, 2020 18:04
OCaml van Laarhoven CPS lenses + eta expansion
(*
OCaml van Laarhoven CPS lenses. https://gist.github.com/tel/08d2a94de21f483cbb20
plus eta expansion
https://stackoverflow.com/questions/29187287/sneaking-lenses-and-cps-past-the-value-restriction
*)
type (-'s, +'t, +'a, -'b) _t =
{ op : 'r. ('a -> ('b -> 'r) -> 'r) -> ('s -> ('t -> 'r) -> 'r) }
type (-'s, +'t, +'a, -'b) t = unit -> ('s, 't, 'a, 'b) _t
#!r6rs
(library (binding)
(export bound?)
(import
(for (only (rnrs base) eq? list not quote lambda eqv? unquote quasiquote) expand)
(for (only (rnrs base) define-syntax) run)
(for (only (rnrs lists) exists) expand)
(for (only (rnrs syntax-case)
quasisyntax unsyntax
syntax-case syntax free-identifier=? syntax->datum datum->syntax)
@leque
leque / tf.ml
Created September 18, 2020 16:41
module TaggedInitial = struct
type _ t =
| Int : int -> int t
| Bool : bool -> bool t
| Eql : ('a t * 'a t) -> bool t
| If : (bool t * 'a t * 'a t) -> 'a t
let term =
If (Bool true, Int 42, Int 0)
@leque
leque / er.ml
Last active September 20, 2022 09:56
module Make() : sig
type field = ..
type 'a field_access =
{ get : field -> 'a option
; set : 'a -> field
; default : 'a
}
type t
object Main {
// 型クラスの定義
trait Show[A] {
def show(x: A): String
}
// 型クラスのインスタンス: Int
implicit def ShowInt: Show[Int] = new Show[Int] {
def show(x: Int) = x.toString
}
module type Show = sig
type t
val show : t -> string
end
module ShowInt : Show with type t = int = struct
type t = int
let show = Int.to_string
end
(use www.css)
(select-module www.css)
(define %an+b
(let ()
(define %+ ($seq ($delim #\+) ($return +)))
(define %- ($seq ($delim #\-) ($return -)))
(define %opt-sign
($optional ($or %+ %-) +))
(define %n ($match1 ('IDENT . 'n)))
(define %-n ($match1 ('IDENT . '-n)))
@leque
leque / s.ml
Created March 14, 2020 15:03
camlp5o pr_scheme.cmo pr_schemep.cmo s.ml > s.scm
type t =
| Leaf of int * string
| Concat of int * t * t
let length = function
| Leaf (i, _) -> i
| Concat (i, _, _) -> i
let leaf s =
Leaf (String.length s, s)