[Haskell] image conversion

Francisco Chaves pachopepe at gmail.com
Mon Jun 23 05:22:21 UTC 2014


Following the type of convert you have

    convert f fig = \(x,y) -> f (fig (x,y))
= { Lambda parameter }
    convert f fig (x,y) = f (fig (x,y))
= { point wise }
    convert f fig (x,y) = (f . fig) (x,y)
= { $ operator }
    convert f fig (x,y) = f . fig $ (x,y)
= { (x,y) is a tuple parameter }
    convert f fig pos = f . fig $ pos


All those definitions for convert are equivalent and do the trick.

Moreover, if you define a Figure data type:

data Figure a = Figure (Pos -> a)

the convert definition is:

convert f (Figure g) = Figure (\pos -> f . g $ pos)

and corresponds to fmap function of the Functor class for the Figure data
type, making a Figure an instance of Functor:

instance Functor Figure where
    fmap = convert


Cheers

Francisco


On Sun, Jun 22, 2014 at 7:13 PM, Peter Kaldenberg <pkaldenberg at gmail.com>
wrote:

> Dear all,
>
> I have a problem, I am working on functional images and have now a problem
> that I need to write a function with the following signature
>
> convert::(a->b)->Figure a ->Figure b
>
> Where Figure a :: Pos -> a and type Pos= (Double, Double)
>
> For instance I have an Image chessBoard.
> chessBoard::Figure Bool
> chessBoard(x,y)= even(round x)==even(round y)
>
> I also have a function boolChar::Bool -> Char
>
> now I want to call convert like convert boolChar chessBoard which will
> give me an Image with the following type Char.
>
> How can I solve this problem?
>
> Many thanks, Peter
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>



-- 
Francisco Jose CHAVES PhD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell/attachments/20140623/40def00a/attachment.html>


More information about the Haskell mailing list