Gilgamesz
Gilgamesz

Reputation: 5073

Make type showable.

How to make type Showable?

type InterpreterMonad  = StateT (Env, Env) (ErrorT String IO ) ()

Normally, I would type deriving Show but I have a type not newtype or data.

P.S. How to write above with newtype?

Upvotes: 1

Views: 351

Answers (1)

Rein Henrichs
Rein Henrichs

Reputation: 15605

type creates a type synonym. If you want to create an instance, you must create it for the target of the type synonym – in this case, StateT (Env, Env) (ErrorT String IO ) (). However, GHC can't derive a Show instance for StateT types because StateT is a wrapper around a function type and GHC can't derive Show for function types.

You could write a newtype as follows:

newtype InterpreterMonad = MkInterpreterMonad (StateT (Env, Env) (ErrorT String IO ) ())

but this won't allow you to derive Show either, since InterpreterMonad is now a wrapper around a wrapper around a function type.

Upvotes: 4

Related Questions