Skip to content

On filter and boolFilter #920

Closed
@andreasabel

Description

@andreasabel

In Data.List.Base, I find

filter :  {P : Pred A p}  Decidable P  List A  List A
boolFilter : (A  Bool)  List A  List A

the latter being deprecated.

I am a bit puzzled by this choice. The current version of filter is simply

filter p = boolFilter (isYes \o p)

I don't question that this specialization gets its own name (as I am generally in favor of fat libraries). However:

  1. In analogy to the naming conventions of Haskell and OCaml, shouldn't filter be the Bool version?
filter : (A  Bool)  List A  List A
  1. The current filter function (which could be called decFilter or filterDec) requires a decidable predicate rather than a simple boolean test, but then throws away the evidence. Shouldn't it rather retain the evidence?
decFilter : (p : Decidable P) -> List A -> \Sigma (List A) (All P)

Analogous cases: partition, span, break, takeWhile, dropWhile.

Design baseline: Don't ask for data that you don't use to produce the result.

See also #263.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions