Giter VIP home page Giter VIP logo

ppx_view_pattern's Introduction

Ppx_view_pattern - Pattern matching on abstract types

This repository contrains some experiments for a ppx rewriter providing pattern matching on abstract types.

Overview

The main motivation for this is to eventually abstract the OCaml AST entirely in ppx_ast, so that ppx rewriters can use a proper API to deal with the OCaml AST and not have to worry about the evolution of the OCaml AST.

The main problem when making the AST abstract is how to deconstruct it. ppx_core provides an Ast_pattern module allowing to do this with combinators. However using them is really painful, and the code is a lot worse that what you can do by just pattern matching on the concrete data types.

This ppx rewriter propose a simple solution to this problem. It rewrites patterm matching of the form:

match%vpat <expr> with
| A x -> f x
| B x -> g x

into some expression where constructors such as A or B are mapped to functions by simply lowercasing their name.

You can see a full example in test/test.ml.

Plan

The plan is:

  • finish this rewriter, in particular add support for record patterns
  • update ppx_ast to abstract the OCaml AST entirely and provides all the necessary builders/patterns
  • upgrade all Jane Street ppx rewriters to use this

This will be a breaking changes for users of ppx_core and [ppx_driver][ppx_driver]. However, once users will have switched, they'll get much better stability guarantees since changes in the parsetree will simply be reflected by forward compatible changes of the ppx_ast API.

Under the hood, ppx_ast will use one the version of the Parsetree supported by ocaml-migrate-parsetree. It will always try to use the highest available version, so that the latest compiler features are available immediately.

Status

Currently nothing appart from this experiment as been done.

ppx_view_pattern's People

Contributors

jeremiedimino avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.