racket / racket/typed-racket

List filters override list element filters

Open
#233 4 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

(I'm pretty sure this is a bug)

Applying a filter to a list seems to remove any filters we previously applied to the list's elements.

#lang typed/racket/base

(: test (-> (Listof (U (List Natural) Boolean)) Boolean))
(define (test expr)
  (if (list? (car expr))
    (if (not (null? expr))
      (= 1 (car (car expr)))
      #f)
    #f))

;; test.rkt:7:11: Type Checker: Polymorphic function `car' could not be applied to arguments:
;; Domains: (Listof a)
;;          (Pairof a b)
;; Arguments: (U Boolean (List Nonnegative-Integer))

Changing the order of the if tests makes the problem go away.

(Credit to the original SO post: http://stackoverflow.com/questions/33475581/how-to-fix-the-return-value-in-this-typed-racket-code/33489459#33489459)

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 Typed Racket example in the issue and reproduce the error from test.rkt, comparing the two orders of the if tests. Trace how the type checker combines filters from list? and the element access; done when both equivalent orders correctly preserve the element filter and the regression is covered by a test.

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.