Skip to content

Odditites regarding Any and typeclasses.

The typechecker seems to be unable to operate on contexts containing "naked" Any, for example:

x :: State [Any] ()
x = put []
    No instance for (MonadState [Any] (StateT [Any] Identity))
      arising from a use of ‘put’

A more minimal self-contained example would be:

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
import GHC.Prim (Any)
class Class a b where method :: a -> b
instance Class a a where method = id
x :: Any -> Any
x = method
    No instance for (Class Any Any) arising from a use of ‘method’

It's quite obvious why this error happens (Any is not a datatype), however it also feels like it shouldn't happen. All of the above code seems to work in 7.8, which is back when Any was a datatype.

Trac metadata
Trac field Value
Version 7.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information