<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">&lt;<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>&gt;</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 -&gt; Bool or<br>
Point -&gt; 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&#39;s Clastic, Conal<br>
Elliott&#39;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) -&gt; Bool<br>
<br>
instance Show CF where<br>
  show _ = &quot;&lt;function&gt;&quot;<br>
<br>
instance Eq CF where<br>
 (==) _ _ = error &quot;No Eq on  Characteristic functions&quot;<br>
<br>
instance Num CF where<br>
  f + g = \pt -&gt; f pt + g pt<br>
  -- ...<br>
  negate f = \(x,y) -&gt; f (negate x, negate y)<br>
<br>
  -- ... rest follows this pattern, Floating, Fractional similar<br>
<br>
If you characteristic function is Point -&gt; 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 (-&gt; Point) &quot;to point&quot;<br>
rather than a characteristic function Point -&gt; 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>