[Haskell-cafe] newbie question how to pass data

Mujtaba Boori mujtaba.boori at gmail.com
Tue Apr 20 04:31:40 EDT 2010


Great job Stephen.
Thank for explaining . I got it to work.


On Tue, Apr 20, 2010 at 9:21 AM, Stephen Tetley <stephen.tetley at gmail.com>wrote:

> Hi
>
> If you are working with characteristic functions (Point -> Bool or
> Point -> Colour...) the common way to do this is to manufacture a Num
> instance for functions. This gives you syntax overloading of the (+,
> -, *) operators. Similarly you might want to overload (or have to
> overload) Floating, Fractional...
>
> Examples using this technique are Jerzy Karczmarczuk's Clastic, Conal
> Elliott's Vertigo, Tangible Values, Pan etc.
>
> To overload Num you have to define Show and Eq instances for functions
> as well. Something along the lines of this is adequate:
>
> type CF = (Double,Double) -> Bool
>
> instance Show CF where
>  show _ = "<function>"
>
> instance Eq CF where
>  (==) _ _ = error "No Eq on  Characteristic functions"
>
> instance Num CF where
>  f + g = \pt -> f pt + g pt
>  -- ...
>  negate f = \(x,y) -> f (negate x, negate y)
>
>  -- ... rest follows this pattern, Floating, Fractional similar
>
> If you characteristic function is Point -> Bool then you also need a
> Num instance for Bool.
>
> All that said, I think your formulation of func above is slightly
> wrong to fit this style. Its forming a function (-> Point) "to point"
> rather than a characteristic function Point -> Bool.
>
> Best wishes
>
> Stephen
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Mujtaba Ali Alboori
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100420/6ebe650b/attachment.html


More information about the Haskell-Cafe mailing list