Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Typeable constraint on Predicate #101

Closed
chessai opened this issue Dec 8, 2023 · 6 comments
Closed

remove Typeable constraint on Predicate #101

chessai opened this issue Dec 8, 2023 · 6 comments

Comments

@chessai
Copy link
Collaborator

chessai commented Dec 8, 2023

No description provided.

@nikita-volkov
Copy link
Owner

Why was it introduced?

@raehik
Copy link
Collaborator

raehik commented Mar 6, 2024

Typeable is used for lots of predicate failure code, via calling typeRep on the predicate (passed around in a Proxy p). It's very useful for the base predicates where meaning is obvious from names and type arguments. Though you might be able to replace it with an associated type class and function to allow "opting out" of the Typeable constraint.

Alternatively, do you mean to clear up the placement of Typeable constraints? A change I made in #83 meant adding more constraints to instances. #98 resolves (and fixes an oversight).

@raehik
Copy link
Collaborator

raehik commented Apr 24, 2024

See how my refined rewrite rerefined resolves this:

class Predicate p where
    -- | The predicate name, as a 'Show'-like (for nice bracketing).
    predicateName :: Proxy# p -> Int -> ShowS

-- | Fill out predicate metadata using its 'Typeable' instance.
--
-- Do not use this for combinator predicates. Doing so will incur
-- insidious 'Typeable' contexts for the wrapped predicate(s).
instance Typeable a => Predicate (Typeably a) where
    predicateName _ d = showsPrec d (typeRep (Proxy @a))

class Predicate p => Refine p a where
    validate :: Proxy# p -> a -> Maybe (RefineFailure String)

-- ...

-- simplified
instance (Predicate l, Predicate r)
  => Predicate (And l r) where
    predicateName _ d = showParen (d > 10) $
          showString "And "
        . predicateName (proxy# @l) 11 . showChar ' '
        . predicateName (proxy# @r) 11

This way, we can continue to use Typeable for convenience for non-combinator predicates, while not incurring insidious Typeable constraints, and retain more control over pretty predicate display in general. Also, TypeReps print inferred/hidden kinds (e.g. And (l :: k1) (r :: k2)), which we can omit.

@raehik
Copy link
Collaborator

raehik commented Jun 12, 2024

Ping. I've rewritten my refined-heavy library binrep to use rerefined which effectively implements the above (except predicate names are calculated type-level) with no issues.

@raehik
Copy link
Collaborator

raehik commented Oct 24, 2024

Ping @chessai @nikita-volkov . I'd still be keen on solving this one way or another.

  • rerefined solves it "for good" but has a completely different design (predicateName is now type PredicateName)
  • move Typeable constraint on predicate kind to class #98 is a good fix
  • alternatively, you could remove support for polykinded predicates. (I've stopped using them personally, plus they don't work with my predicate simplifier in rerefined.)

@chessai
Copy link
Collaborator Author

chessai commented Nov 15, 2024

This is solved now by @raehik's work :)

@chessai chessai closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants