How to fix DatatypeContexts?

Sjoerd Visscher sjoerd at w3future.com
Thu Jul 18 13:57:42 CEST 2013


What I always do is to write it like this:

equal pair at 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 <voldermort at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users





More information about the Glasgow-haskell-users mailing list