Functional programming is a programming paradigm which primarily uses functions as means for building abstractions and expressing computations that comprise a computer program.
0
votes
3answers
34 views
Caching function result on c#
Let us have this kind of code:
Function<int,int> someFunc=(x)=>{
//SomeCalc
return y;
}
than I want to use my function that way:
int result;
if(someFunc(k)!=0)
{
...
0
votes
0answers
3 views
How to setup and teardown functional test data in Geb grails
I have many working/passing functional geb/spock tests (each extending GebReportingSpec) that are testing a web application with test data all created from the BootStrap.groovy at the beginning of the ...
0
votes
0answers
27 views
Unifying Types in Haskell
I'm kind of stuck with an assignement concerning my exams. I want to find out the types of those two functions by applying the unifying algorithm by hand:
map map
(\x -> x >>= (\y -> y))
...
4
votes
1answer
134 views
Functional non recursive approach to looping in Haskell
I use Haskell for my programming during leisure these days. Being a programmer in imperative languages for over 8 years, it is tough to wrap my head around some functional constructs (especially the ...
2
votes
2answers
69 views
FoldLeft using FoldRight in scala
While going through Functional Programming in Scala, I came across this question:
Can you right foldLeft in terms of foldRight? How about the other way
around?
In solution provided by the ...
0
votes
2answers
99 views
Designing Testable Functional Code
I like the idea of writing pure functions, but I'm having trouble understand ways to combine them that lead to testable code. I'm used to extracting classes and then stubbing appropriately, and feel ...
8
votes
0answers
261 views
Are there problems that can't be solved efficiently without arrays? [duplicate]
For someone used to imperative programming, it's sometimes hard to write efficient code in functional languages without using arrays/vectors. However, it seems there's always a smart way of doing it. ...
1
vote
3answers
50 views
Loops and variable scope in R
I have following for loop in R:
v = c(1,2,3,4)
s = create.some.complex.object()
for (i in v){
print(i)
s = some.complex.function.that.updates.s(s)
}
# s here has the right content.
Needless ...
3
votes
1answer
70 views
Compute a chain of functions in python
I want to get the result of a chain of computations from an initial value. I'm actually using the following code:
def function_composition(function_list, origin):
destination = origin
for ...
1
vote
1answer
48 views
clojure sum of all the primes under 2000000
It's a Project Euler problem .
I learned from Fastest way to list all primes below N in python
and implemented a clojure :
(defn get-primes [n]
(loop [numbers (set (range 2 n))
primes []]
...
2
votes
3answers
105 views
Built in f# operator to compose functions with the same input but different outputs?
I understand the << compose operator takes two functions that both take in and return the same type. e.g. (lhs:'a -> 'a) -> (rhs:'a -> 'a) -> 'a
I often find myself wanting ...
5
votes
1answer
171 views
F# and modeling of the inheritance
my question relates to a way how to deal with the inheritance in functional way in F#. To describe it a little, I give a simple example. Suppose we want to model a world consisting of various kinds of ...
1
vote
1answer
24 views
To execute or not execute a callback in python
I am confronted with python 2.7 callbacks from a library that I use.
I have to use some callback functions from Cherrypy auth examples in my code. (These callbacks return a function that can evaluate ...
6
votes
3answers
137 views
Evaluation of nullary functions in Haskell
Suppose you have a nullary function in haskell, which is used several times in the code. Is it always evaluated only once? I already tested the following code:
sayHello :: Int
sayHello = ...
1
vote
5answers
41 views
pass built-in methods into variables/arguments
I'm learning javascript right now, seems like beautiful functional language to me, it is wonderful move from PHP, I should have done this earlier. Although, I cannot figure this one out:
var v1 = ...