So if a language provides higher order procedure then I can have procedure that returns procedure... something like
(define (Proc a b c) (lambda (x) ( // method body here in terms of a b c and x)))
To create new proc I would just do something like..
(define ProcA (Proc a1 b1 c1)) // Would create ProcA that has 1 argument
Similar task...
Is it recommended to always have exhaustive pattern matches in Haskell, even for "impossible" cases?
For example, in the following code, I am pattern matching on the "accumulator" of a foldr. I am in complete control of the contents of the accumulator, because I create it (it is not passed to me as input, but rather built within my func...
I have some Haskell code that does work correctly on an infinite list, but I do not understand why it can do so successfully. (I modified my original code -- that did not handle infinite lists -- to incorporate something from some other code online, and suddenly I see that it works but don't know why).
myAny :: (a -> Bool) -> [a] -> Bo...
I am working through "Real World Haskell", which led to to a free PDF called "A tutorial on the universality and expressiveness of fold". It makes the point that a "fold" is "universal". I am wrestling with his definition of "universal", and would like to hear the from those who have already invested time digesting it: Please explain in ...
What is meant by the statement that functional programs are "more tractable mathematically"?
...
Are there any known principles, best-practices and design patterns that one can follow while writing code in a functional programming language?
...
I've recently been learning about functional programming (specifically Haskell, but I've gone through tutorials on Lisp and Erlang as well). While I found the concepts very enlightening, I still don't see the practical side of the "no side effects" concept. What are the practical advantages of it? I'm trying to think in the functional m...
Suppose I write a program using immutable data structures in Java. Even though it is not a functional language, it should be able to execute parallely. How do I ensure that my program is being executed using all the cores of my processer? How does the computer decide which code can be run parallely?
P.S. My intent in asking this questi...
I am writing a Scheme-like in interpreter. It seems natural that the Scheme-like interpreter ought to work well with any object that implements IEnumerable.
The interpreter does not allow for mutation - no functions with side effects are exposed.
Because IEnumerable is not cloneable, (see here ), I can't implement iteration over the l...
I have two Haskell functions, both of which seem very similar to me. But the first one FAILS against infinite lists, and the second one SUCCEEDS against infinite lists. I have been trying for hours to nail down exactly why that is, but to no avail.
Both snippets are a re-implementation of the "words" function in Prelude. Both work fine...
This question might be naive as I'm new to ColdFusion programming.
I have a task for which I have written a function, f1, inside a component. I want to call f1 from another function, f2 defined in the same component.
f2 is being called in a cfm file.
My question - Is this the right way to do it? Can I invoke f1 from f2?
I can as well...
After some experience with functional languages, I'm starting to use recursion more in Java - But the language seems to have a relatively shallow call stack of about 1000.
Is there a way to make the call stack bigger? Like can I make functions that are millions of calls deep, like in Erlang?
I'm noticing this more and more when I do Pr...
I've been reading a bit lately about functional programming and I am trying to grok the Y-Combinator. I understand that you can use the Y-Combinator to effectively implement recursion in a language that doesn't support recursion directly. However, every language that I'm likely to use already supports recursion so I'm not sure how usef...
Correct me if I'm wrong, but it seems like algebraic data types in Haskell are useful in many of the cases where you would use classes and inheritance in OO languages. But there is a big difference: once an algebraic data type is declared, it can not be extended elsewhere. It is "closed". In OO, you can extend already defined classes. Fo...
I just mistakenly did something like this in C++, and it works. Why can I do this?
int main(int argc, char** argv) {
struct MyStruct
{
int somevalue;
};
MyStruct s;
s.somevalue = 5;
}
Now after doing this, I kind of remembered reading about this trick someplace, a long time ago, as a kind of poor-man's funct...
Im trying to print the output of function only when it is true but so far all attempts have been unsuccsessful.
Something on the lines of
let printFactor a b = if b then print_any((a,b))
where b is a boolean and a is an integer.
When I try it I get
val printFactor : 'a -> bool -> unit
Any suggestions?
EDIT:
To put things in...
When writing GUI apps I use a top level class that "controls" or "coordinates" the application. The top level class would be responsible for coordinating things like initialising network connections, handling application wide UI actions, loading configuration files etc.
At certain stages in the GUI app control is handed off to a differe...
Phil Bagwell, in his 2002 paper on the VList data structure, indicates that you can use a VList to implement a persistent hash table. However, his explanation of how that worked didn't include much detail, and I don't understand it. Can anybody give me a more detailed explanation, or even examples?
Further, it appears to me from what I ...
Hello all. I'm a "good" programmer. I know Haskell, OCaml, and other functional languages very well. I know also Smalltalk, Objective-C, and other OO languages. I spend my time on LtU, I know a fair amount about programming language theory and compiler design, and above all, I'm, ahem, incredibly brilliant.
That said, I'm also hungry, a...
I know that the map function takes each element of a list (a sequence) and applies a function to it. Recursively (and without respect to termination conditions, etc)
map(s, f) = f(s.head) :: map(s.tail, f)
I am looking for a function that does something like
foo(s, f) = f(s) :: map(s.tail, f).
So a 'mapper' where the mapping func...