Skip to content

Instantly share code, notes, and snippets.

@ytomino
Created April 25, 2021 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytomino/097b4ded22783dcda9be8682d4cb7c67 to your computer and use it in GitHub Desktop.
Save ytomino/097b4ded22783dcda9be8682d4cb7c67 to your computer and use it in GitHub Desktop.
GADTの型パラメータをObj.magicで一致させることで無関係な後続の式の型チェックを回避できる
module type T1 = sig
type t (* any abstract type *)
val one: t
end;;
module M1: T1 = Int;;
type 'a repr = C1: M1.t repr (* GADT is needed *)
let one: string =
let C1 = (Obj.magic C1: string repr) in (* force M1.t = string *)
M1.one;; (* !!! *)
print_string one;; (* segmentation fault *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment