Created
February 21, 2010 06:19
-
-
Save Neurogami/310164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Going through the Lisperati haskell tutorial (http://www.lisperati.com/haskell/ht1.html) | |
There is one page that has me stumped: http://www.lisperati.com/haskell/ht6.html | |
In particular, this line: | |
where clip g = concatMap ((uncurry $ clipTriangle i).(partition g)) t | |
Here's what I think is happening, from assorted Googling: | |
'partition' has type (a -> Bool) -> [a] -> ([a],[a]) , but if called with just a | |
partitioning function then it returns a another function that takes a list and returns | |
a tuple with the partitioned array. The items in the tuple are each an array, | |
contents decided on whether the partitioning function returned true or false on | |
each item of the initial array. | |
So, (partition g) | |
is (so to speak) | |
fn_that_gives_us_a_tuple :: [a] -> ([a], [a]) | |
'uncurry' has type (a -> b -> c) -> (a,b) -> c | |
Given a function that acts on two args (and returns something) it returns a function | |
that takes a single arg; this arg is a tuple made up of what would have been the | |
separate args. | |
Both return the same results. | |
clipTriangle has type (Point -> Point -> Point) -> [Point] -> [Point] -> [Polygon] | |
If called with a single argument (a function that acts on two points and returns a point) | |
then it returns a new function, one of type [Point] -> [Point] -> [Polygon] | |
If *that* function is uncurried, we get a function of type ( [Point] , [Point] )-> [Polygon] | |
I *think* that | |
uncurry $ clipTriangle i | |
is the same as | |
uncurry (clipTriangle i) | |
whihc produces something like | |
fn_uncurried_clipTriangle :: [Point] -> [Point] -> [Polygon] | |
so | |
concatMap ((uncurry $ clipTriangle i).(partition g)) t | |
is (so to speak) | |
concatMap ( fn_uncurried_clipTriangle . fn_that_gives_us_a_tuple) t | |
concatMap takes a function and an array and maps the function to the array items, producing | |
a new array; that mapping function is the composition | |
( fn_uncurried_clipTriangle . fn_that_gives_us_a_tuple) | |
Is this correct? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment