On Mon, Jul 01, 2013 at 05:07:00PM +0200, Vlatko Basic wrote:
> Hello Cafe!
> 
> I had a (simplified) record
> 
>   data P = P {
>     a :: String,
>     b :: String,
>     c :: IO String
>     } deriving (Show, Eq)
> 
> but to get automatic deriving of 'Show' and 'Eq' for 'data P' I have
> created 'newtype IOS' and its 'Show' and 'Eq' instances
> 
>   newtype IOS = IO String
>   instance Show (IOS) where show _ = "(IO String) function"
>   instance Eq   (IOS) where _ == _ = True

An Eq instance for something containing IO is bound to lead to puzzlement
somewhere down the line.  I think you're better off defining something like

    data P_lesser = P_lesser {
        a_lesser :: String,
        b_lesser :: String
    } deriving (Show, Eq)

    to_lesser p = P_lesser (a p) (b p)

and just factoring everything through "to_lesser" when you want to compare
or show.

Tom

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

Reply via email to