<div dir="ltr">Great job <font color="#888888">Stephen</font>. <br>Thank for explaining . I got it to work.<br><br><br><div class="gmail_quote">On Tue, Apr 20, 2010 at 9:21 AM, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi<br>
<br>
If you are working with characteristic functions (Point -> Bool or<br>
Point -> Colour...) the common way to do this is to manufacture a Num<br>
instance for functions. This gives you syntax overloading of the (+,<br>
-, *) operators. Similarly you might want to overload (or have to<br>
overload) Floating, Fractional...<br>
<br>
Examples using this technique are Jerzy Karczmarczuk's Clastic, Conal<br>
Elliott's Vertigo, Tangible Values, Pan etc.<br>
<br>
To overload Num you have to define Show and Eq instances for functions<br>
as well. Something along the lines of this is adequate:<br>
<br>
type CF = (Double,Double) -> Bool<br>
<br>
instance Show CF where<br>
show _ = "<function>"<br>
<br>
instance Eq CF where<br>
(==) _ _ = error "No Eq on Characteristic functions"<br>
<br>
instance Num CF where<br>
f + g = \pt -> f pt + g pt<br>
-- ...<br>
negate f = \(x,y) -> f (negate x, negate y)<br>
<br>
-- ... rest follows this pattern, Floating, Fractional similar<br>
<br>
If you characteristic function is Point -> Bool then you also need a<br>
Num instance for Bool.<br>
<br>
All that said, I think your formulation of func above is slightly<br>
wrong to fit this style. Its forming a function (-> Point) "to point"<br>
rather than a characteristic function Point -> Bool.<br>
<br>
Best wishes<br>
<font color="#888888"><br>
Stephen<br>
</font><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
</div><div><div></div><div class="h5"><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Mujtaba Ali Alboori<br>
</div>