Hi,

I am trying to understand how to define instances for Read class for a
user defined type. 

 

This is the sample code I wrote, but I am not able to get it correctly.
So, let me know what's wrong with this program:

 

 

module Mark where

 

data Mark = Mark Int deriving (Show)

 

instance Read Mark where

 

            readsPrec _ str = [(Mark x, t') | ("mark",t) <- reads str, 

                                                             (x,t') <-
reads t

 

When I run it in ghci:

 

*Mark> reads "mark 5" :: [ (Mark,String)]         ( I am intentionally
using mark in lowercase) 

 []

 

Why is the output coming out as [] as against expected output [(Mark 5,
"")] ?

 

-Anurag

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to