이 (다소 무의미한) 모듈은 컴파일 : 나는 f
의 인스턴스의 정의를 제거하면, 나는 방법의 기본을 상속를 기대컴파일 오류가
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ExplicitForAll #-}
module Foo where
class A t where
f :: forall x m. Monoid x => t m -> m
f = undefined
instance A [] where
f = undefined
그리고 같은 금액.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ExplicitForAll #-}
module Foo where
class A t where
f :: forall x m. Monoid x => t m -> m
f = undefined
instance A [] where
그러나 이것은 작동하지 않습니다.
• Could not deduce (Monoid x0)
arising from a use of ‘Foo.$dmf’
from the context: Monoid x
bound by the type signature for:
f :: Monoid x => [m] -> m
at src/Foo.hs:10:10-13
The type variable ‘x0’ is ambiguous
These potential instances exist:
instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’
instance Monoid Ordering -- Defined in ‘GHC.Base’
instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
...plus 7 others
(use -fprint-potential-instances to see them all)
• In the expression: Foo.$dmf @[]
In an equation for ‘f’: f = Foo.$dmf @[]
In the instance declaration for ‘A []’
내가 상상 x0
가 삽입되는 위치 내가 알고하지 않기 때문에,이 오류를 읽는 방법을 잘 모르겠어요 : GHC 8.0.2이 오류를 제공합니다. 두 번째 예제가 컴파일되지 않는 이유는 무엇입니까?
GHC 문제를 열었습니다. https://ghc.haskell.org/trac/ghc/ticket/14266 –