
In `containers`, Data.Sequence.Internal defines a Foldable instance for `Seq` with method definitions for `length` and `null` that I'm struggling to understand: https://github.com/haskell/containers/blob/master/containers/src/Data/Sequen... #if MIN_VERSION_base(4,8,0) length = length {-# INLINE length #-} null = null {-# INLINE null #-} #endif further down the file there are also explicit top-level definitions for these functions: https://github.com/haskell/containers/blob/master/containers/src/Data/Sequen... -- | \( O(1) \). Is this the empty sequence? null :: Seq a -> Bool null (Seq EmptyT) = True null _ = False -- | \( O(1) \). The number of elements in the sequence. length :: Seq a -> Int length (Seq xs) = size xs So the intent seems clear, but I don't understand how the instance method definitions are valid. The imports of Both Prelude and Data.Foldable don't include `length` or `null`: https://github.com/haskell/containers/blob/master/containers/src/Data/Sequen... So the RHS definitions should plausibly resolve to the top-level functions, but when I try to define a similar type class instance GHC tells me: ‘method’ is not a (visible) method of class ‘Class’ and in any case I'd expect `length = length` to yield an infinite loop, regardless of any other bindings in the outer scope. How is Data.Sequence.Internal getting away with this??? -- Viktor.