racket / racket/typed-racket

Documentation Request: declare-refinement

Open
#683 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

What version of Racket are you using?

v6.12

What program did you run?
#lang typed/racket #:with-refinements

(: seven? (-> Integer Boolean))
(define (seven? x)
  (equal? x 7)
  )

(declare-refinement even?)
(declare-refinement seven?)
What should have happened?

This might be a documentation request, but I'm not sure how to use (declare-refinement) from the documentation. The only use of it is in the Typed Racket codebase is in a unit test with even?, which does seem to work.

The documentation only says that the identifier should be a predicate, but even? appears to be annotated with some additional propositions.

[even? (-> -Int B : (-PS (-not-type 0 -One) (-not-type 0 -Zero)))]

How should one annotate an arbitrary predicate so that it is usable as a refinement type?

If you got an error message, please include it here.
 mismatch in proposition
  expected: ((: x (Refinement Integer seven?)) | (! x (Refinement Integer seven?)))
  given: (Top | Top)
  in: (equal? x 7)

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 with the documentation entry for declare-refinement and the Typed Racket unit test using even?, then compare them with the shown seven? example and its type-checker error. Document how an arbitrary predicate should be annotated for use as a refinement type, including the relevant proposition behavior, and ensure the example's expected usage is clear.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.