Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 484
Julien Langlois Avatar asked Oct 21 '22 08:10

Julien Langlois


1 Answers

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.

like image 50
Joachim Breitner Avatar answered Oct 24 '22 10:10

Joachim Breitner