In the following code I got warning Orphan instance: instance (MonadIO m, Monad m) => GenerateUUID m
instance (MonadIO m, Monad m) => GenerateUUID m where
generateUUID = liftIO nextRandom
According to it the solution is either
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.
(or disable the warning hat Internet also suggest)
My problem is that I'm not able to find how to wrap the type with a newtype?
You can define a newtype wrapper like this:
If we also want to say "I want
Footo have the same instances forFunctor,Monad,Applicative... thatmhas, the only difference being that the methods useFoo m ainstead ofm a" we can use the-XDerivingViaextension:Any time the compiler complains about a missing instance for
Foo, add it to thederivingclause.A slight refinement. Suppose we also wanted to "inherit"
SemigroupandMonoidinstances. For example:IO ()is aMonoid, so we might wantFoo IO ()to be aMonoidas well. We need a separatederivingclause:Why a separate clause? Because the typeclasses have different kinds.
Functorhas kind(Type -> Type) -> Constraintand we are declaring the instance forFoo m, which has kindType -> Type.Meanwhile,
Semigrouphas kindType -> Constraintand we are declaring the instance forFoo m a, the "fully applied" type constructor with kindType.