I just discovered power of syb library and trying to find its limits.
I've got everywhere
working:
> :set -XDeriveDataTypeable
> :set -XGeneralizedNewtypeDeriving
> import Data.Generics
> newtype MyInt = MyInt Int deriving (Show, Eq, Num, Ord, Data)
> incMyInt (MyInt i) = MyInt $ 1 + i
> printMyInt (MyInt i) = putStrLn $ "MyInt = " ++ show i
> :t mkT incMyInt
mkT incMyInt :: Typeable a => a -> a
> :t mkM printMyInt
<interactive>:1:5: error:
• Couldn't match type ‘()’ with ‘MyInt’
Expected type: () -> IO ()
Actual type: MyInt -> IO ()
mkT and mkM look similar and I don't see the reason why mkM is not working for printMyInt
> :t mkM
mkM :: (Monad m, Typeable a, Typeable b) => (b -> m b) -> a -> m a
> :t mkT
mkT :: (Typeable a, Typeable b) => (b -> b) -> a -> a
even pure
:t mkM pure
<interactive>:1:1: error:
• Could not deduce (Typeable b0) arising from a use of ‘mkM’
from the context: (Monad m, Typeable a)
bound by the inferred type of
it :: (Monad m, Typeable a) => a -> m a
at <interactive>:1:1
ghc 8.10.7 and syb 0.7.2.1