Ambiguous defaults
Andrew J Bromage
ajb@spamcop.net
Fri, 3 Jan 2003 10:18:03 +1100
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