Instances of Read and Show

Ingo Sander ingo@ele.kth.se
Thu, 29 Mar 2001 17:10:10 +0200 (MET DST)


I have a question concerning the Read and Show classes.

I have read the Haskell 98 report (section 6.3.3 The Read and Show
Classes), but I still do not figure out how to make instances.

I have a simple data type:

data TVal a =  Abst   
	     | Prst a

I managed to define the function show, so that I can use it with the data
type TVal
 
instance (Show a) => Show (TVal a) where
	 show Abst     = "_"
	 show (Prst x) = show x

Signals> [Prst 1, Abst, Prst 2]
[1,_,2] :: [TVal Integer]

which is what I want to have.

But how do I make a Read instance?

I still do not understand the meaning of 'readsPrec' and
'readList' (and not of 'showPrec' and 'showList') either. 

Can somebody explain to me or give me a good reference so that I can make
TVal an instance of the classes Read and Show. 

Thanks in advance for your help!

Ingo Sander