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

Fails to build on GHC 8.2 #95

Closed
RyanGlScott opened this issue Apr 1, 2017 · 2 comments
Closed

Fails to build on GHC 8.2 #95

RyanGlScott opened this issue Apr 1, 2017 · 2 comments

Comments

@RyanGlScott
Copy link

When doing some field testing today, I noticed that swagger2 fails to build with GHC 8.2:

$ cabal build
Building swagger2-2.1.3...
Preprocessing library swagger2-2.1.3...
[ 9 of 14] Compiling Data.Swagger.Internal.Schema ( src/Data/Swagger/Internal/Schema.hs, dist/build/Data/Swagger/Internal/Schema.o )

src/Data/Swagger/Internal/Schema.hs:638:25: error:
    • Overlapping instances for GSumToSchema (C1 c U1)
        arising from a use of ‘gdeclareNamedSumSchema’
      Matching instances:
        two instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: gdeclareNamedSumSchema
      In an equation for ‘gdeclareNamedSchema’:
          gdeclareNamedSchema = gdeclareNamedSumSchema
      In the instance declaration for ‘GToSchema (C1 c U1)’
    |
638 |   gdeclareNamedSchema = gdeclareNamedSumSchema
    |                         ^^^^^^^^^^^^^^^^^^^^^^

src/Data/Swagger/Internal/Schema.hs:763:84: error:
    • Couldn't match kind ‘k’ with ‘*’
      ‘k’ is a rigid type variable bound by
        the instance declaration
        at src/Data/Swagger/Internal/Schema.hs:762:10-48
      When matching the kind of ‘proxy’
      Expected type: proxy (C1 c U1)
        Actual type: proxy (C1 c U1)
    • In the third argument of ‘gsumConToSchemaWith’, namely ‘proxy’
      In the second argument of ‘(.)’, namely
        ‘gsumConToSchemaWith (Inline nullarySchema) opts proxy’
      In the expression:
        pure . gsumConToSchemaWith (Inline nullarySchema) opts proxy
    • Relevant bindings include
        proxy :: proxy (C1 c U1)
          (bound at src/Data/Swagger/Internal/Schema.hs:763:21)
        gsumToSchema :: SchemaOptions
                        -> proxy (C1 c U1)
                        -> Schema
                        -> WriterT AllNullary (Declare (Definitions Schema)) Schema
          (bound at src/Data/Swagger/Internal/Schema.hs:763:3)
    |
763 |   gsumToSchema opts proxy = pure . gsumConToSchemaWith (Inline nullarySchema) opts proxy
    |                                                                                    ^^^^^

The issue is that starting in GHC 8.2, the datatypes in GHC.Generics became poly-kinded. There are two ways one could fix this problem:

  1. Use an explicit kind signature for GSumToSchema:

    diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs
    index ae6a7b2..1f6b3dd 100644
    --- a/src/Data/Swagger/Internal/Schema.hs
    +++ b/src/Data/Swagger/Internal/Schema.hs
    @@ -727,7 +727,7 @@ gdeclareNamedSumSchema opts proxy s
     
     type AllNullary = All
     
    -class GSumToSchema f where
    +class GSumToSchema (f :: * -> *) where
       gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Defi
     
     instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where

    This would be identical to inferred kind signature prior to GHC 8.2.

  2. Generalize the kind signature of GToSchema:

    diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs
    index ae6a7b2..d5965d5 100644
    --- a/src/Data/Swagger/Internal/Schema.hs
    +++ b/src/Data/Swagger/Internal/Schema.hs
    @@ -404,7 +404,7 @@ sketchStrictSchema = go . toJSON
           where
             names = HashMap.keys o
     
    -class GToSchema (f :: * -> *) where
    +class GToSchema (f :: k -> *) where
       gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schem
     
     instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where

Which option sounds better to you?

@phadej
Copy link
Collaborator

phadej commented Apr 1, 2017

I assume both variants works with GHC>=7.8? I have no opinion on this, I assume generics functors are always instantiated as * -> * when used in deriving (Generic)?

@RyanGlScott
Copy link
Author

I assume both variants works with GHC>=7.8?

Yes, both options are backwards compatible back to GHC 7.8.

I have no opinion on this, I assume generics functors are always instantiated as * -> * when used in deriving (Generic)?

Yes. It's only Generic1 that is allowed to take advantage of things of kind k -> *.

albertov added a commit to albertov/swagger2 that referenced this issue May 26, 2017
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