Skip to content

[discussion] Catch contradictory predicates when declaring refined type  #14

@kachayev

Description

@kachayev

That's a kinda tricky thing to do...

From "obvious" steps we can take:

  1. Mark types & predicates as :seq, :num and :string and converge the predicates tree to the most "common" one. In case of mismatch show the error

  2. For ordering predicates, we can do basic checks with :num types using simple rules to deal with intervals

  3. Anything else...?

A few example of what I want to "catch":

(r/refined s/Str (r/Greater 0))
(r/refined [s/Str] (r/First (r/Greater 0)))
(r/And (r/Greater 0) r/NonEmpty))
(r/refined (r/refined [s/Str] r/NonEmpty) (r/Greater 0))
(r/refined (r/NonEmptyListOf s/Str) (r/First (r/Greater 0)))

More on "dependent types":

(r/And (r/Greater 0) (r/Less 0)) ;; (r/Equal 0)
(r/And (r/Greater 0) (r/Less -1)) ;; error
(r/Or (r/Greater 0) (r/Greater 10)) ;; (r/Greater 0)
(r/refined NonEmptyStr NonEmpty) ;; NonEmptyStr

Neat and very nice to have:

(r/refined [s/Str] (Less 0)) ;; error suggesting to use (On count (Less 0))
(r/refined [s/Str] (On count NonEmpty)) ;; error becuase `count` returns to numeric
(r/refined double (On count NonEmpty)) ;; error becuase `count` does not accept double

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions