The Semantics of Rank Polymorphism

07/01/2019
by   Justin Slepak, et al.
0

Iverson's APL and its descendants (such as J, K and FISh) are examples of the family of "rank-polymorphic" programming languages. The principal control mechanism of such languages is the general lifting of functions that operate on arrays of rank (or dimension) r to operate on arrays of any higher rank r' > r. We present a core, functional language, Remora, that captures this mechanism, and develop both a formal, dynamic semantics for the language, and an accompanying static, rank-polymorphic type system for the language. Critically, the static semantics captures the shape-based lifting mechanism of the language. We establish the usual progress and preservation properties for the type system, showing that it is sound, which means that "array shape" errors cannot occur at run time in a well-typed program. Our type system uses dependent types, including an existential type abstraction which permits programs to operate on arrays whose shape or rank is computed dynamically; however, it is restricted enough to permit static type checking. The rank-polymorphic computational paradigm is unusual in that the types of arguments affect the dynamic execution of the program – they are what drive the rank-polymorphic distribution of a function across arrays of higher rank. To highlight this property, we additionally present a dynamic semantics for a partially erased variant of the fully-typed language and show that a computation performed with a fully-typed term stays in lock step with the computation performed with its partially erased term. The residual types thus precisely characterise the type information that is needed by the dynamic semantics, a property useful for the (eventual) construction of efficient compilers for rank-polymorphic languages.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
12/31/2019

Introduction to Rank-polymorphic Programming in Remora (Draft)

Remora is a higher-order, rank-polymorphic array-processing programming ...
research
06/15/2019

Approximate Normalization for Gradual Dependent Types

Dependent types help programmers write highly reliable code. However, th...
research
11/13/2017

A Type Checking Algorithm for Higher-rank, Impredicative and Second-order Types

We study a type checking algorithm that is able to type check a nontrivi...
research
06/10/2023

The Design Principles of the Elixir Type System

Elixir is a dynamically-typed functional language running on the Erlang ...
research
03/15/2023

Quantitative Global Memory

We show that recent approaches of static analysis based on quantitative ...
research
05/01/2018

Live Functional Programming with Typed Holes

This paper develops a dynamic semantics for incomplete functional progra...
research
04/27/2023

Traced Types for Safe Strategic Rewriting

Strategy languages enable programmers to compose rewrite rules into stra...

Please sign up or login with your details

Forgot password? Click here to reset