[Haskell-cafe] equations and patterns

Dan Mead d.w.mead at gmail.com
Thu May 31 03:35:29 EDT 2007


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 <stefan at cs.uu.nl> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070531/1b9d6547/attachment-0001.htm


More information about the Haskell-Cafe mailing list