Giter Club home page Giter Club logo

ppx_viewpattern's Introduction

ppx_viewpattern

ci workflow status GitHub release status opam package status

Transformation for view patterns in OCaml. Attempts to imitate Haskell view patterns.

Installation

opam install ppx_viewpattern

Usage

In dune:

(preprocess (pps ppx_viewpattern))

Syntax

Use [%view? pat when exp] as a pattern to apply exp to whatever the pattern is matching and match the result of the exp application against pat. Analogous to the Haskell view pattern exp -> pat.

See example/ for example usage.

Supported in:

  • match ... with ... cases,
  • function ... cases,
  • fun ... -> ... arguments,
  • let ... in ... expression binding left-hand sides,
  • try ... with ... cases,
  • nested inside the pat and exp parts of a view pattern itself.

Caveats

A view pattern disables redundant-case and partial-match warnings for the corresponding match/function.

Currently unsupported in:

  • let ... definition left-hand sides (at top level or in modules).

ppx_viewpattern's People

Contributors

sim642 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ppx_viewpattern's Issues

Pattern guards

Haskell has another feature called "pattern guards":

There are severely outdated ports of them to OCaml:

There are also OCaml RFCs:

Although this ppx is currently explicitly for view patterns, it might be relatively easy to swallow ppx_pattern_guard functionality for transforming matches while sharing some of the underlying infrastructure. Neither feature subsumes the other, but there are big similarities, so it might be worth generalizing this ppx.

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.