Skip to content

define-metafunction does not check type signature on LHS #255

@digama0

Description

@digama0
#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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions