Overlapping instances for aeson

Viewed 76

After installing new version of aeson (ghc-pkg list | grep aeson shows aeson-1.4.7.1) I now have a following error:

RoseTree.hs:17:69: error:
    • Overlapping instances for aeson-1.2.1.0:Data.Aeson.Types.ToJSON.RecordToPairs
                                  JSON.Value
                                  (dlist-1.0:Data.DList.Internal.DList
                                     aeson-1.2.1.0:Data.Aeson.Types.Internal.Pair)
                                  JSON.Zero
                                  (M1
                                     S
                                     ('MetaSel
                                        ('Just "value")
                                        'NoSourceUnpackedness
                                        'NoSourceStrictness
                                        'DecidedLazy)
                                     (Rec0 a))
        arising from the 'deriving' clause of a data type declaration
      Matching instances:
        two instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
      (The choice depends on the instantiation of ‘a’
       To pick the first instance above, use IncoherentInstances
       when compiling the other instance declarations)
    • When deriving the instance for (JSON.ToJSON (RoseTree a))
   |
17 |                    deriving (Show, Generic, Functor, JSON.FromJSON, JSON.ToJSON)
   |                                                                     ^^^^^^^^^^^
Failed, one module loaded.

My source code is following:

{-# LANGUAGE DeriveAnyClass      #-}
{-# LANGUAGE DeriveFunctor       #-}
{-# LANGUAGE DeriveGeneric       #-}
{-# LANGUAGE FlexibleInstances   #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE IncoherentInstances #-}

module RoseTree where

import qualified Data.Aeson   as JSON
import           Data.Maybe
import           Data.Monoid
import           Data.Tree
import           GHC.Generics (Generic)

data RoseTree a = RoseTree { value :: a, children :: [RoseTree a]}
                   deriving (Show, Generic, Functor, JSON.FromJSON, JSON.ToJSON)

How to get rid of this error? Thanks in advance.

1 Answers

It turns out that cabal got stuck on earlier version of aeson 1.2.1.0 and nothing helped with fixing it by ordinary means. Problem is solved by switching to Nix.

Related