[Haskell-cafe] Proposal: deriving ShallowEq?

Henning Thielemann lemming at henning-thielemann.de
Tue Jul 19 04:10:29 EDT 2005


On Tue, 19 Jul 2005, Ben Lippmeier wrote:

> An example, using some arbitrary data type "Thingo":
>
>  > class ShallowEq a where
>  >  shallowEq  :: a -> a -> Bool
>
>  > data Thingo a b
>  >	= TOne   a
>  >	| TTwo   a b Int Char Float
>  >	| TThree Int Char b b
>
> Questions:
>   1) Does anyone know a better/existing way to implement ShallowEq that
> doesn't involve enumerating all the constructors in the data type?

A more general approach are projection functions like

getTOne :: Thingo a b -> Maybe a
getTOne (TOne x) = Just x
getTOne _        = Nothing

Then you can map the values to be compared into a Maybe and you need only
a shallowEq for Maybe.



More information about the Haskell-Cafe mailing list