racket / racket/redex

define-metafunction does not check type signature on LHS

Open
#255 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
112
Forks
42
PR merge metrics
No merged PRs in 30d

Description

#lang racket
(require redex)

(define-language A (N ::= 0 1 2))

(define-metafunction A
  flip : N -> N
  [(flip 1) ()]
  [(flip ()) 1])

(term (flip 1))
; flip: codomain test failed for (), call was (flip 1) [,bt for context]
(term (flip ()))
; flip: (flip ()) is not in my domain [,bt for context]

Ideally, the clauses in the definition of flip would be rejected because () does not match the grammar N, so they can never be used correctly. Checking #:pre and #:post conditions would also be great, but I'm not sure this is possible. (Also I wouldn't be too surprised if it is possible to write expressions that can't be typechecked at function declaration time, but there are lots of examples like this one where the pattern definitely has empty intersection with the grammar, so an error message seems warranted.)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the define-metafunction entry point and reproduce the example showing clauses whose left-hand patterns do not match N. Determine how declaration-time grammar checks should report the invalid clauses, and verify that valid definitions and the existing runtime errors remain unchanged. The issue also mentions #:pre and #:post checks as a possible follow-up or scope question.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.