If you want to enforce associativity just create your own Eq instance and make it a pattern there.
Initially when I started doing Haskell it seemed that you could just type an equation of constructors and have it enforced as a rule. This actually isn't the case (someone correct me if I'm wrong) but it is being researched ATM. Dan On 5/31/07, Stefan Holdermans <[EMAIL PROTECTED]> wrote:
Mingli, > > class Lattice e where > > join :: e -> e -> e > > meet :: e -> e -> e > > > > -- associative law > > join x (join y z) = join (join x y) z > > join (join x y) z = join x (join y z) If you are not to sell your soul to advanced and perhaps obscure type hacking, you cannot express laws like this *in* Haskell. More concretely, one usually does not provide such laws as default implementations of a class' methods. Instead, they are stated in, for instance, comments and the documentation that goes with your library. These then form an informal obligation for programmers that provide instances of your class to let these instances obey the laws. If you provide an instance of the class you could use testing framework, e.g., QuickCheck [1], to assert that the required properties hold. Cheers, Stefan [1] www.cs.chalmers.se/~rjmh/QuickCheck/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe