repl example
> data Piece = Bishop | Rook
> Bishop
"No instance for (Show Piece) arising from a use of ‘print’"
Haskell is complaining that it doesn't have know how to serialize the value Bishop
into a String
(because Piece
isn't an instance of the Show typeclass).
Fix as follows:
This instructs the compiler to create the obvious Show
instance for Piece
.
Note
Haskell cannot derive a Show
instance for all types - data types containing functions in particular are a problem because there is no obvious way to show
them.
Last update:
January 15, 2023
Created: January 15, 2023
Created: January 15, 2023