POV-Ray : Newsgroups : povray.off-topic : Monads in C# : Re: Monads in C# Server Time
29 Jul 2024 22:22:17 EDT (-0400)
  Re: Monads in C#  
From: Darren New
Date: 3 Jul 2011 17:21:51
Message: <4e10dd6f$1@news.povray.org>
On 7/3/2011 14:16, Darren New wrote:
> of functions that only take one argument and only yield one result,

Oh, and the same mechanism lets you return multiple results.

f(x, y)[z]     (in C syntax)
is really just f(x, y, z) in a functional language.
f(x, y) would, instead of an array or list, return a lambda that when you 
pass it an integer argument it would return the appropriate element of the 
result.  So you could assign the result of f(x, y) to a variable and treat 
it like an array, but in the math, it's just another function invocation. 
And obviously f(x) is similarly a 2-dimensional array, where f(x)(y,z) is 
accessing the 2D array at index y, z.

Basically, currying means that f(x,y,z) is identical to f(x)(y)(z). Sort of 
like the way C unifies 2D arrays as a 1D array of 1D arrays. C only has to 
state the rules of how a 1D array works, and then you can compose them up 
into as many dimensions as you want. With currying, you only have to state 
the rules for taking one argument and returning one result, and curry up as 
many arguments and return results as you want.

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.