pycoq icon indicating copy to clipboard operation
pycoq copied to clipboard

Encoding of objects

Open ejgallego opened this issue 4 years ago • 0 comments

As of today, OCaml types are encoded by ppx_python as more or less straight lists.

This is OK, however not very idiomatic, and limited in some cases (maybe GADTs?)

On the other hand, ADT do admit a different encoding with objects, of the form:

type a = A of a * int | B of int

to

abstract class a { ... }
abstract class a_A inherits a { a &a_val ; int int_val }
abstract class a_B inherits a { int : int_val }
....

That would be quite convenient, seems both in terms of implementing patterns such as visitor, or using the upcoming pattern matching extension for Python as noted by @thierry-martinez

ejgallego avatar Sep 23 '21 15:09 ejgallego