Comments (4)
Why do things in so complicated way when we can (at least advocate for) using -Werror=missing-methods
ghc-proposals/ghc-proposals#544
And as far as I see, the strategy you propose won't work for http-api-data
which has circular definitions of members (and that's the reason anyclass
deriving works). i.e. there are defaults in place.
from http-api-data.
Why do things in so complicated way when we can (at least advocate for) using -Werror=missing-methods ghc-proposals/ghc-proposals#544
- Because I didn't know it existed.
- Because the mechanism allows for customising the error message (but this is not relevant in this particular context because as you pointed out, circular definition)
from http-api-data.
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.
from http-api-data.
This is very much about improving the API
As said, the approach proposed won't work (prove me wrong) as all methods of From/ToHttpApiData
already have default definitions, and changing that is a big change.
I assume the bad thing about DeriveAnyClass is that it succeeds for FromHttpApiData
as the class is circular, so is "trivially" implemented for any type. But that is exactly what I discuss in the ghc-proposals issue. That's bad.
{-# 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 -Wall
):
Circular.hs:15:21: warning: [-Wmissing-methods]
• No explicit implementation for
either ‘foo’ or ‘bar’
• In the instance declaration for ‘FooBar U’
|
15 | data U = U deriving FooBar
| ^^^^^^
I like to fix the cause of issues, not to band-aid them all over the place. Making -Wmissing-methods
being an error in GHC is one potential fix to this (and other) issues. And in fact, that train is slowly moving, but could move faster if people weight in.
Because the mechanism allows for customising the error message (
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 Don't use anyclass deriving with class C
which is incorrect.
from http-api-data.
Related Issues (20)
- FormUrlEncoded is vulnerable to HashDOS attacks. HOT 1
- Support GHC-9.6
- How to deal with generic deriving for non-flat records
- GFromForm for Bool
- Allow base-4.20 HOT 2
- allow cookie-0.5
- Test failures with GHC 8.2.1rc-2 HOT 3
- Add instances for `SetCookie` HOT 4
- Incorrect lower-bounds
- Support for Cabal 2.2? HOT 10
- Add instances for Data.Fixed
- Why don't toQueryParam or toUrlPiece actually url-encode the data? HOT 2
- toUrlPiece for NominalDiffTime loses precision HOT 6
- Allow base-4.12.0.0 HOT 3
- Why does `showTextData` convert everything to lower case HOT 3
- FromForm and ToForm instances for (,) and Either HOT 5
- Allow base-4.13.0.0 HOT 5
- could not parse: `' (input does not start with a digit) HOT 1
- ToHttpApiData instances for ToJSON instances
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-api-data.