custom type errors - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Will

is there any way to use the custom type error machinery to override the default "no instance for X arising from use of Y"? i'm admittedly pretty new to type-level programming

Will
  • for a particular class, that is
Will

wow, yes, thanks. exactly like that. i'd seen that bit of documentation but i guess it didn't click since i'm playing with an empty type class; didn't occur to me that I could just drop the where. also ended up needing to tinker with OverlappingInstances.

Will

tangentially related question, is it possible to write a type family which, given a typeclass and a list of types, produces a constraint which holds if any one of the types is a member of the class? I have something like the Member construct from polysemy in mind, but i'm not sure exactly how to port that over to my use case

Will
type family Member (c :: Type -> Constraint) (ts :: [Type]) :: Constraint where
  Member c '[]      = True ~ False
  Member c (t : ts) = ?? (c t) (Member c ts)

i've gotten this far but have no idea what ?? should be or if a fitting expression is even possible

Lysxia

No it's not possible.

Lysxia

The very nature of type classes is that anyone could declare an instance anywhere, so it's not possible to tell that an instance definitely does not exist.

Will

Gotcha, thanks. Won't waste any more time scratching my head on this one then