What I always do is to write it like this: equal pair@Pair{} = foo pair == bar pair
The {} syntax ensures that it doesn't matter how complex the Pair constructor is. Sjoerd On Jul 18, 2013, at 1:52 PM, harry <volderm...@hotmail.com> wrote: > All of the proposed solutions seem to rely on pattern matching in the > constructor, which isn't always feasible. Here's a slightly better example: > > data Pair a = (Num a, Eq a) => Pair {x::a,y::a} > > equal :: Pair a -> Bool > equal pair = (foo pair) == (bar pair) > > foo pair = (x pair) * (y pair) > > bar pair = (y pair) + (x pair) > > Now imagine that foo and bar are part of a library which I don't control, or > that for some other reason I can't just change foo and bar to take only the > components of Pair (e.g. it's a complex type with numerous components and > subcomponents). > > > > -- > View this message in context: > http://haskell.1045720.n5.nabble.com/How-to-fix-DatatypeContexts-tp5733103p5733110.html > Sent from the Haskell - Glasgow-haskell-users mailing list archive at > Nabble.com. > > _______________________________________________ > Glasgow-haskell-users mailing list > Glasgow-haskell-users@haskell.org > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users