Opened 3 years ago

Closed 3 years ago

#12438 closed bug (fixed)

DeriveDataTypeable - deriving instance Data (Mu (Const ()))

Reported by: lspitzner Owned by:
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.0.1
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2726
Wiki Page:

Description (last modified by lspitzner)

{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
import qualified Data.Data

data Mu f = Mu (f (Mu f))
deriving instance Data.Data.Data (Mu (Const ()))

produces

    • No instance for (Data (Const () (Mu (Const ()))))
        arising from a use of ‘k’
    • In the expression: (z Mu `k` a1)
      In an equation for ‘gfoldl’: gfoldl k z (Mu a1) = (z Mu `k` a1)
      When typechecking the code for ‘gfoldl’
        in a derived instance for ‘Data (Mu (Const ()))’:
        To see the code I am typechecking, use -ddump-deriv
      In the instance declaration for ‘Data (Mu (Const ()))’

while other type constructors work, e.g.

deriving instance Data.Data.Data (Mu [])
deriving instance Data.Data.Data (Mu ((,) ()))

i am not sure if #10835 is related.

Change History (6)

comment:1 Changed 3 years ago by lspitzner

Description: modified (diff)

comment:2 Changed 3 years ago by bgamari

Keywords: deriving added

comment:3 Changed 3 years ago by RyanGlScott

I had to make some changes to your code to get that exact error message. Here is what I tried:

{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, StandaloneDeriving #-}
module T12438 where

import Control.Applicative (Const(..))
import qualified Data.Data

data Mu f = Mu (f (Mu f))
deriving instance Data.Data.Data (Mu (Const ()))

Note the addition of FlexibleInstances. Also, Const wasn't in scope in your original program — I assume you are referring to the Const from Control.Applicative? If so, there's a simple explanation for why that program won't compile — Const doesn't have a Data instance. Sure enough, this program compiles just fine:

{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, StandaloneDeriving #-}
module T12438 where

import Control.Applicative (Const(..))
import qualified Data.Data

deriving instance (Data.Data.Data a, Data.Data.Data b) => Data.Data.Data (Const a b)

data Mu f = Mu (f (Mu f))
deriving instance Data.Data.Data (Mu (Const ()))

In light of this, there's no bug in DeriveDataTypeable - it's just a Haskell library design question of whether Const should have a Data instance or not (I wouldn't be opposed to introducing one).

comment:4 Changed 3 years ago by RyanGlScott

Differential Rev(s): Phab:D2726
Milestone: 8.2.1

I've submitted a patch for this, as discussed at https://mail.haskell.org/pipermail/libraries/2016-November/027396.html.

comment:5 Changed 3 years ago by Ryan Scott <ryan.gl.scott@…>

In 3bd1dd4/ghc:

Add Data instance for Const

Summary:
Fixes #12438. As discussed on the Haskell libraries mailing list here:
https://mail.haskell.org/pipermail/libraries/2016-November/027396.html

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2726

GHC Trac Issues: #12438

comment:6 Changed 3 years ago by RyanGlScott

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.