[Haskell-cafe] Need feedback on my Haskell code

CK Kashyap ck_kashyap at yahoo.com
Thu Jul 30 07:11:07 EDT 2009

Thanks David 

From: david48 <dav.vire+haskell at gmail.com>
To: CK Kashyap <ck_kashyap at yahoo.com>
Cc: Chaddaï Fouché <chaddai.fouche at gmail.com>; haskell-cafe at haskell.org
Sent: Wednesday, July 29, 2009 4:43:52 PM
Subject: Re: [Haskell-cafe] Need feedback on my Haskell code

On Wed, Jul 29, 2009 at 12:04 PM, CK Kashyap<ck_kashyap at yahoo.com> wrote:
> map maySwitch . unfoldr go $ (x1,y1,0)

I'm not an expert and I might say things the wrong way or without the
required rigor, so with this disclaimer here's my explanation :

go calculates a step of the line, given the current coordinates and
the error value
it returns nothing if the line is done.

unfoldr go calculates a list of lines coordinates, keeping calling go,
and stopping when go returns nothing.

maySwitch takes a coordinate, and switches the x and y values
depending on the axis we're following
map maySwitch does the same for the entire list of coordinates.

when you compose the two,
map maySwitch . unfoldr go  is then a function that takes initial
coordinates, makes a list of coordinates and may switch the x's and
y's depending on the axis we're following.

Now (.) takes two functions, namely map maySwitch and unfoldr go. If
you don't write the $, what you actually mean is
(map maySwitch) . ( unfoldr go (x1,y1,0))

this ( unfoldr go (x1,y1,0)) is not of the right type for (.) : it
should take a parameter and return a value, but here it just returns a

so you have to find a way to give (x1,y1,0) to the whole composed
function  map maySwitch . unfoldr go.

the obvious way to do it is by writing:

( map maySwitch . unfoldr go ) (x1,y1,0 )

the $ is just a more readable way to write it : since $ binds with
less priority, in
map maySwitch . unfoldr go $ (x1,y1,0)
what's on the right of $ will be applied to what's on the left


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090730/1ef59336/attachment.html

More information about the Haskell-Cafe mailing list