in reply to Re^16: Near-free function currying in Perl
in thread Near-free function currying in Perl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^18: Near-free function currying in Perl
by tmoertel (Chaplain) on Nov 23, 2004 at 01:23 UTC | |
Keep in mind that the following code is probably too small, too simple, and too limited to be useful for drawing general conclusions. The best you can hope for is to get a taste. To draw inferences about the whole cuisine from this tiny sampling would be a mistake. First some library functions: Read more... (1151 Bytes)
Now let us write code using the above vocabulary. First, the preliminaries: Let us start with some simple functions to show the general idea: Now let us build further to create a function to compute vector dot products: So far, we have computed only with numbers. Let us now turn to data. One common programming task is to compute the combinations that can be generated by taking one element from a set of sets. (I selected this problem because various implementations can be found on Perl Monks for comparison.) Here's my implementation: Building further, let's compute power sets. One common method of computing the power set of a set S is the following:
Each step in the original method maps directly to a stage in the composition pipeline, the output of each stage becoming the input of the next. This ends my example. You are welcome to code your own versions of these functions for comparison. Because these functions are so simple, the comparisons might not yield much insight. A more useful exercise might be for you to write FP and non-FP code to solve more complex problems and then compare the coding experiences instead of the code itself. Cheers, Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder | [reply] [d/l] [select] |