Functional programming is a programming paradigm which primarily uses functions as means for building abstractions and expressing computations that comprise a computer program.
1
vote
0answers
33 views
Parsing command line args and executing a function in scala
I am trying to parse commandline arguments and execute a function that takes the parameters upon successful extraction of the parameters. I have an object called CurrencyExchangeRunner where the main ...
0
votes
0answers
26 views
Commercial usage and integrability of functional languages
I have a strong interest in functional languages, because they have so many advantages, but I don't know if they are really used in practice and how well they can be integrated into a mainstream Java, ...
0
votes
2answers
96 views
Is it possible to do that in Scala (without mutating the internal state of a class)?
Let's say, there is a class called RemoteIdGetter. It returns a key from a server. But it only makes a request to the server if the key is not "fresh" enough, meaning the last time it's been ...
-7
votes
1answer
37 views
Why it is not possible to index result of a function directly in Matlab? [closed]
Suppose I have some function which returns matrix. Let it be size function, but this is just an example.
>> size(lab)
ans =
1998 1999 3
so I can do
>> ...
1
vote
3answers
45 views
What is a functional-style replacement for this loop?
nums = [2 5 3 7]
result = []
result.push {x:nums[0]}
for n in nums.slice(1)
result.push {n:n + result[-1].x}
log result
# [{x:2} {x:7} {x:10} {x:17}]
This is hard to express functionally using ...
1
vote
4answers
55 views
my combinations function returns an empty list
I am working on S-99: Ninety-Nine Scala Problems and already stuck at question 26.
Generate the combinations of K distinct objects chosen from the N elements of a list.
After wasting a couple hours, I ...
0
votes
1answer
10 views
Using glmm_funs.R?
I am fitting a GLMM and I had seen some examples where is used the function: overdisp_fun, deļ¬ned in glmm_funs.R, but I don't know which package contain them or how can I call it from R, can somebody ...
1
vote
2answers
128 views
Functional way to implement a thread safe shared counter
I'm relatively new to Scala and functional programming, and I like the idea that using immutable objects I can avoid many thread safety pitfalls. One thing still haunts me, and it's the classical ...
12
votes
2answers
108 views
Haskell Pattern Matching Fails on Negative Number
The Haskell compiler throws an error on the following function:
balancedMax :: Int -> Int -> Int
balancedMax -1 _ = -1
balancedMax _ -1 = -1
balancedMax a b = max a b
Flipping the sign solves ...
0
votes
2answers
42 views
Scala Yield behaves differently than Scala Map
I trying to compose and initialize an Array in a single line, roughly equivalent to this:
var characterMap = new Array[List[ActorRef]](sizeX*sizeY)
characterMap.indices.foreach(characterMap(_) = ...
0
votes
0answers
43 views
Is any normalization of a function to a curried form considered currying?
I was reading a blog post about combining higher order functions and it provided a C# example of "currying".
The examples look like:
public static Func<T1, Func<T2, T3>> Curry<T1, T2, ...
-1
votes
0answers
67 views
When is it appropriate to use functional features in an OO language? [closed]
I was recently asked this question by a new starter and was stumped to give a meaningful answer. When is it appropriate?
0
votes
3answers
68 views
recursion in ocaml nested lists
I am new to Ocaml and am writing code to substitute elements in nested Ocaml lists. My code is as follows:
type 'a sexp = S of 'a | L of 'a sexp list
My substitution function(it replaces all ...
0
votes
1answer
52 views
ocaml mutual recursion error
I am new to Ocaml and want help with recursive function defined on a recursive data type. I have defined a data type as follows
type 'a slist = S of 'a sexp list
and
'a sexp = Symbol of ...
2
votes
1answer
49 views
How do I convert a function into point free form?
Let's say I have a JavaScript function
function f(x) {
return a(b(x), c(x));
}
How would I convert that into a point free function? through composing functions? Also are there resources for more ...