I have a problem understanding the function composition and the concept of partially applied functions.
Actually I'm writing a small raytracer and have some example implemenentations which I dont understand exactly. Here is one example which I dont understand (https://github.com/ryanl/haskell-raytracer/blob/master/src/RayTracer.hs): It's the function which detects the color of a ray:
srdetectcolour' :: Scene -> Ray -> Maybe (Surface, Scalar) -> Colour
srdetectcolour' scene (Ray rx rv) (Just (s,d)) = zipWith (+) lightadded (surface_colour s)
where lightsvisible :: [Light]
lightsvisible = lightsvisiblefrom intersectpoint scene
lightadded :: Colour
lightadded = (foldr (zipWith (+)) black . map effectivelight) lightsvisible
effectivelight :: Light -> Colour
effectivelight (v,c) = map (round . (*10000.0) . (/ (vector_sum ((intersectpoint - v) * (intersectpoint - v)))) . fromInteger) c
intersectpoint = (rx + (mult d rv))
I'm interested in the (sub)-function lightadded
where the foldr
-part represents a partially applied function (when I'm right). The concept of the function is clear, one wants to add the light of visible lightsource in a point on a surface. For every visible lightsource there is a function effectivelight
mapped over. What I dont understand is the last parameter of the foldr
-function ( . map effectivelight) and the complete construction of the function. Can someone explain to me the function (in parts) and the construction of the function? Maybe one can write the function in a more intuitiv way?