snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
152 stars 63 forks source link

MonoFoldable requires FlexibleContexts #152

Closed jchia closed 6 years ago

jchia commented 6 years ago

I don't know whether there is a regression but there is a difference between mono-traversable-1.0.4.0 and mono-traversable-1.0.5.0:

With 1.0.4.0, the following code compiles, but with 1.0.5.0, FlexibleContexts is needed. Without it, there is a compiler error. The code was tested on nightly-2017-12-08 and lts-10.0

Code:

{-# LANGUAGE NoImplicitPrelude, GeneralizedNewtypeDeriving, TypeFamilies #-}

module Lib where

import ClassyPrelude

newtype Foo = Foo ByteString deriving MonoFoldable
type instance Element Foo = Word8

Error:

/home/jchia/hs/test/src/Lib.hs:7:39: error:
    • Non type-variable argument
        in the constraint: Eq (Element ByteString)
      (Use FlexibleContexts to permit this)
    • In the expression:
        ghc-prim-0.5.1.1:GHC.Prim.coerce
          @(Eq Element ByteString =>
            Element ByteString -> ByteString -> Bool)
          @(Eq Element Foo => Element Foo -> Foo -> Bool)
          oelem
      In an equation for ‘oelem’:
          oelem
            = ghc-prim-0.5.1.1:GHC.Prim.coerce
                @(Eq Element ByteString =>
                  Element ByteString -> ByteString -> Bool)
                @(Eq Element Foo => Element Foo -> Foo -> Bool)
                oelem
      When typechecking the code for ‘oelem’
        in a derived instance for ‘MonoFoldable Foo’:
        To see the code I am typechecking, use -ddump-deriv
      In the instance declaration for ‘MonoFoldable Foo’
  |            
7 | newtype Foo = Foo ByteString deriving MonoFoldable
  |                                       ^^^^^^^^^^^^
jchia commented 6 years ago

I wonder whether this is due to a ghc bug. https://ghc.haskell.org/trac/ghc/ticket/8883

jchia commented 6 years ago

So, according to the discussion in the GHC trac, I suppose this is the expected behavior because of oelem.