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.

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

Reply via email to