Why does the following code not compile even if I added the Typeable boundary to satisfy the cast function's requirements?
import Data.Data
a :: Maybe Int
a = cast f
where
f :: Typeable a => a
f = undefined
app/Main.hs:6:5: error:
• No instance for (Typeable a0) arising from a use of ‘cast’
• In the expression: cast f
In an equation for ‘a’:
a = cast f
where
f :: Typeable a => a
f = undefined
|
6 | a = cast f
| ^^^^
Maybe Int should implement the type class because the following code compiles.
import Data.Data
b :: String
b = show $ typeRep (Proxy :: Proxy (Maybe Int))
(I'm not asking how to cast a value, e.g., from Int to String. I'm just curious about this strange error.)
GHC: 9.2.2