-
Notifications
You must be signed in to change notification settings - Fork 43
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
Preventing the anyclass deriving of ToHttpApiData and FromHttpApiData #124
Comments
Why do things in so complicated way when we can (at least advocate for) using And as far as I see, the strategy you propose won't work for |
|
I’m very much for advocating your ghc-proposal but how is it relevant as a solution for present problems; the proposal is neither accepted nor implemented? This is very much about improving the API not about being able to give a recommendation in the documentation. |
As said, the approach proposed won't work (prove me wrong) as all methods of I assume the bad thing about DeriveAnyClass is that it succeeds for {-# LANGUAGE DeriveAnyClass #-}
class FooBar a where
foo :: a -> a
foo = bar
bar :: a -> a
bar = foo
{-# MINIMAL foo | bar #-}
data U = U deriving FooBar should error. Luckily it at least warns today (even without
I like to fix the cause of issues, not to band-aid them all over the place. Making
I don't see that to be valuable at all. GHC is definitely capable of saying that "you forgot to define methods". And that is the best you can do, as mentioning DeriveAnyClass is incorrect. Modifying the example in issue description, note no DerivingAnyClass: {-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas, -Wall #-}
module PreventAnyClassDeriving (A (..), C (..), C' (..), C'' (..), MkTypeError) where
import Data.Kind (Type)
import GHC.TypeLits (ErrorMessage (ShowType, Text, (:<>:)), TypeError)
type MkTypeError :: k -> Type
type family MkTypeError c where
MkTypeError c =
TypeError ('Text "Don't use anyclass deriving with class " ':<>: 'ShowType c)
type PreventAnyClassDeriving c = MkTypeError c ~ ()
class C a where
f :: a -> Int
default f :: PreventAnyClassDeriving C => a -> Int
f = error "someone removed the PreventAnyClassDeriving constraint"
class C' where
f' :: Int
default f' :: PreventAnyClassDeriving C' => Int
f' = error "someone removed the PreventAnyClassDeriving constraint"
class C'' a b where
f'' :: a -> b
default f'' :: PreventAnyClassDeriving C'' => a -> b
f'' = error "someone removed the PreventAnyClassDeriving constraint"
data A = MkA
-- "ordinary" empty instance declaration
instance C A still errors with |
Hi @fizruk! I'm a long-time Servant user (and thus of
http-api-data
), and I'd like to suggest a solution to prevent theanyclass
deriving strategy ofToHttpApiData
andFromHttpData
via a solution that @MangoIV came up with:What do you think of this?
The text was updated successfully, but these errors were encountered: