racket / racket/typed-racket

`reverse` could infer more from `List*` types with homogeneous elements

Open
#73 0 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

Obviously reverse can’t fully compute the output type of a variable-length list with heterogeneous elements. But with a variable-length list of homogeneous elements, the length of the output type can be inferred to be the same as the input type.

In the first two examples below, that use List, reverse correctly preserves the list length in the output type. But with List*, it weakens the type from a two-or-more list to an any-length list.

(define-type ExactlyTwoIntegers (List Integer Integer))
(define exactly-two : ExactlyTwoIntegers '(1 2))
(mb-reverse exactly-two) ; type = ExactlyTwoIntegers

(define-type OneIntOneBool (List Integer Boolean))
(define int-bool : OneIntOneBool '(1 #t))
(mb-reverse int-bool) ; type = (List Boolean Integer)

(define-type AtLeastTwoIntegers (List* Integer Integer (Listof Integer)))
(define at-least-two : AtLeastTwoIntegers '(1 2))
(reverse at-least-two) ; type = (Listof Integer)
;; but it could be (List* Integer Integer (Listof Integer))

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

The issue names no source file or test entry point. Start by reproducing the three Typed Racket examples and inspect how reverse handles List and List* types; done means a homogeneous List* preserves its minimum length while heterogeneous lists retain their existing behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
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.