在以下代码中,我得到了警告Orphan instance: instance (MonadIO m, Monad m) => GenerateUUID m
instance (MonadIO m, Monad m) => GenerateUUID m where
generateUUID = liftIO nextRandom
据此解决方案是
move the instance declaration to the module of the class or of the type, or
wrap the type with a newtype and declare the instance on the new type.
((或禁用警告帽,Internet也建议)
我的问题是我找不到如何用新类型包装类型?
会是类似的东西
newtype Foo m = Foo { unFoo :: m }
instance (MonadIO m, Monad m) => GenerateUUID (Foo m) where
generateUUID = liftIO nextRandom
为了避免孤立实例警告,您的实例声明必须伴随以下至少一项:
定义newtype
满足第二个条件,尽管使用实例可能会更加复杂。