# Generic Programming in OCaml

**Authors:** Florent Balestrieri (ENSTA-ParisTech), Michel Mauny (Inria Paris)

arXiv: 1812.11665 · 2019-01-01

## TL;DR

This paper introduces a generic programming library for OCaml that leverages recent language features to facilitate type reflection, extensibility, and concise recursive function definitions, demonstrated through a type-safe deserialization case study.

## Contribution

It presents a novel OCaml library utilizing recent language features to enable flexible, type-safe generic programming and recursive traversal capabilities.

## Key findings

- Library supports various generic programming approaches via views.
- Provides powerful combinators for recursive functions over complex types.
- Enables type-safe deserialization respecting type abstraction.

## Abstract

We present a library for generic programming in OCaml, adapting some techniques borrowed from other functional languages. The library makes use of three recent additions to OCaml: generalised abstract datatypes are essential to reflect types, extensible variants allow this reflection to be open for new additions, and extension points provide syntactic sugar and generate boiler plate code that simplify the use of the library. The building blocks of the library can be used to support many approaches to generic programming through the concept of view. Generic traversals are implemented on top of the library and provide powerful combinators to write concise definitions of recursive functions over complex tree types. Our case study is a type-safe deserialisation function that respects type abstraction.

---
Source: https://tomesphere.com/paper/1812.11665