Ambiguous defaults
Thomas L. Bevan
thomas_bevan@aardvark.net.au
Wed, 8 Jan 2003 17:50:28 +1100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've never been very clear on this.
As I understand it, Andrew's code specifies a Compound class where the type
the compound determines the type (and consequently class) of the value of
"decompose c".
In Ferenc's example, the Compound class specifies that the class of the value
of "decompose c" will be Component.
So, Ferenc's example is ambiguous in so far as a Compound type does not
determine the Component type, but it does determine the Class and isn't that
all we need to know to be able to call the 'property' function?
Tom
On Fri, 3 Jan 2003 10:18 am, Andrew J Bromage wrote:
> G'day all.
>
> On Thu, Jan 02, 2003 at 05:49:41PM +0100, Ferenc Wagner wrote:
> > What's the way to express the following: a compound object
> > is generally made up of two components with identical type.
>
> This should work:
>
> \begin{code}
> module Test where
>
> class Component b where
> property :: b -> Int
>
> class (Component b) => Compound a b | a -> b where
> decompose :: a -> (b,b)
> additive :: a -> Int
> additive x = property l + property r
> where (l,r) = decompose x
> \end{code}
>
> Cheers,
> Andrew Bromage
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+G8o4Gse0w80KF2gRApvGAKCFRiK2V7ThDlLHcEl8upL6W57sRQCgjCeP
CgQJ2uArswCo0z/CS2caEq0=
=N/bh
-----END PGP SIGNATURE-----