{-# MINIMAL f, g | () #-}?

I have an issue, that is morally similar to this:

import Data.Proxy (Proxy)
import Data.Kind (Type)

-- law: \a -> poly a (root a) ≡ 0
class C (a :: Type) where
  poly :: Proxy a -> Double -> Double
  poly _ x = 2 * x + 5
  root :: Proxy a -> Double
  root _ = -2.5
  {-# MINIMAL poly, root | () #-}

data A
instance C A where
  poly _ x = x + 5
  -- gives warning correctly because of missing `root`
  -- root _ = -5

data B
--- shouldn't give warning
instance C B

Using the default methods should only be possible if all of them are defaulted.
Otherwise it should give a warning.
How can I do this? The MINIMAL pragma doesn’t do what I want.

Would it help to combine poly and root into a single member, polyRoot?

2 Likes

Ingenious, albeit annoying, solution! I could in fact do that for any such class, but you’d need a helper record which is annoying.

Maybe you can make this work in combination with type families too

Well, given that there is a compatibility condition between them it does seem that they should be defined in the same value.

Isn’t a “compatibility-condition” any law that involves multiple members of the class?

Ah, nice perspective. I guess it is!

Made a bug report: ` {-# MINIMAL f, g | () #-}` pragma doesn't work as expected (#21782) · Issues · Glasgow Haskell Compiler / GHC · GitLab

1 Like