简体   繁体   中英

Writing a Show instance for Data.Functor.Compose without FlexibleContexts

I'm experimenting with Data.Functor.Compose and wanted to write a Show instance for it when trying things out in ghci. What I have (which is working) is:

{-# LANGUAGE FlexibleContexts #-}
instance (Show (f (g a))) => Show (Compose f g a) where
    show = show . getCompose

What I was wondering is: is there a way to write this Show instance without FlexibleContexts?

I don't think it is possible. To quote the GHC documentation for FlexibleContexts :

In Haskell 98, the assertions in the context of the instance declaration must be of the form C a where a is a type variable that occurs in the head.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM