Functional programming is a programming paradigm based upon building abstractions using functions, avoiding side effects and change of state. Pure functional programming is thread safe.
2
votes
0answers
30 views
Stacking Free Monads
I'm learning about the Free monads, and I've put together a simple example in Scala where I use them to define two domain specific languages.
The first monad deals with the side effects of a ...
3
votes
0answers
36 views
Markov processes with higher order functions in R
I'm looking for a clean way to run simulations where each iteration depends on the result of the preceding iteration in a "functional style." For example, say we want to take a normally distributed ...
2
votes
5answers
28 views
Return the maximum number in each array using map
function each(coll, f) {
if (Array.isArray(coll)) {
for (var i = 0; i < coll.length; i++) {
f(coll[i], i);
}
} else {
for (var key in coll) {
f(coll[key], key);
}
}...
0
votes
1answer
13 views
Are data races intrinsic to imperative programming and an obstacle for parallel computing?
I don't study this area of computing to be honest. Actually my references is some web and academic articles then I'm insecure but curious about some concepts of parallel computing.
I've formulated ...
1
vote
1answer
77 views
How does “multi-argument” functional composition work (e.g. fmap . fmap)?
When we have the expression:
(fmap . fmap) function nested_functor
I would expect it to translate to something like
fmap (fmap function nested_functor)
Though it surprisingly seems to behave as
...
0
votes
1answer
15 views
ImmutableJS: Merging two Lists by values
I have two Immutable.JS lists:
const numbers = fromJS([2]);
const moreNumbers = fromJS([1, 2]);
How can I merge these by value and preserving order to produce the following list?
[2, 1]
The idea ...
1
vote
2answers
73 views
Curry Anonymous Function
I am new to Haskell and functionall programming and am a little confused. Why can not I curry an anonymous function, or is it even possible?
I have the following piece of code:
largestDivisible :: (...
-1
votes
2answers
38 views
Merge two lists python [duplicate]
a = [0, 2, 4]
b = list(map(lambda x: x+1, a))
merged list c = [0, 1, 2, 3, 4, 5]
c = [a[0], b[0], a[1], b[1] ... ]
Can I achieve the result with functional programming ?
Instead of just looping ?
...
0
votes
1answer
16 views
Data validation using RxJS
I have the following function that validates that rangeFrom is not superior to rangeTo and that the rangeFrom does not already exist in the list of ranges.
How can rewrite this using RxJS?
const ...
2
votes
1answer
98 views
How to move from external function to functional lens
On my journey to start getting better with functional programming, I discovered, with the help of a member of the SO family, what lens. I even made some research on it with the links down below to ...
0
votes
1answer
49 views
Swapping two successive elements in a list
I have a list of elements and I would like to create a Haskell function of this type :
swap :: [Token] -> [Token]
Given this data : data Token = Number | Operator
In the function I would like ...
1
vote
1answer
55 views
Roslyn - How can I expand auto-implemented properties in a syntax tree?
Background:
Using Roslyn with C#, I am trying to expand auto-implemented properties, so that the accessor bodies can have code injected by later processing. I am using StackExchange.Precompilation ...
0
votes
1answer
19 views
Make Custom Control Generic
I have created a Custom JavaFX Control, Call it ComboBoxTablePopup, it's a Generic Control witch takes a list of items of type S from the user.
Internally, i have used some sort of filtering in the ...
1
vote
0answers
28 views
AVL trees in scheme
I'm trying to implement an AVL tree in Scheme. My approach to this task was to initially make an initial tree representation and progressively implement AVL properties after completing so. I've tried ...
0
votes
0answers
14 views
dynamic scope vs lexical scope results
what will be returned using chez scheme - dynamic scope?
> (define x 0)
> ((lambda(x) x) 10)
> x
Our opinion is that the last value of x will be returned: 10 (when it passed as a parameter ...
0
votes
1answer
43 views
Action<T> delegate in function signature parameter - unclear about type
I have a working piece of C# code that uses the Renci.SshNet package. I'm uploading a file, and the relevant function has the following signature:
public void UploadFile(Stream input, string path, ...
0
votes
2answers
24 views
Curried functions: how to optimize them
I'm relatively new to functional programming and libraries such as ramda.js but one thing I found very useful is the possibility of currying functions.
Using curried functions I write very often ...
0
votes
0answers
23 views
Is there a inverse of the function list-ref in scheme racket? [duplicate]
Hi evrybody i'm looking for a function that do the opposit of list-ref
instead of giving a ref an it gives you an item of the list,
you give an item of the list and it gives you it's ref.
Anyone have ...
0
votes
3answers
36 views
How can I calculate a file checksum in Elixir?
I need to calculate the md5 sum of a file in Elixir, how can this be achieved?
I would expect that something like:
iex(15)> {:ok, f} = File.open "file"
{:ok, #PID<0.334.0>}
iex(16)> :...
-1
votes
1answer
24 views
Ramda fails with setDate function
I'm trying to learn functional javascript with Ramda and I'm stuck with this. Here is the JS Bin: http://jsbin.com/kozeka/
And this is the code:
const date = new Date()
const addDays = R.add(date....
4
votes
0answers
69 views
F# and protected access modifier [duplicate]
You can't define protected class members in F# due in part to how they complicate the functional nature of the language. (The Book of F# - Dave Fancher).
I am new to functional programming, and the ...
0
votes
1answer
57 views
Scala validation - Right-biased Either
At last Scala 2.12 has Right-biased Either. I heard it can be used for validation purpose but I cannot imagine this. I am not able to find good example.
Could somebody explain me how this monad could ...
2
votes
2answers
52 views
What does my slot class miss that std::function has?
I wrote my own "slot" aka "callable wrapper" because I wanted to provide member function slot rebinding on other objects (i.e. I needed a way to store the member function pointer and a pointer to the ...
2
votes
1answer
73 views
Haskell Higher Order Functions
I have a homework on higher order functions in Haskell and I'm having a little trouble getting started.
If I could get some help and explanation on the first question, I'm confident I can finish the ...
4
votes
2answers
52 views
Pointfree recursion in JS with ramda
I am learning about pointfree functions and am trying to implement this recursive null remover in that style.
Works, but is not pointfree:
function removeNulls(obj) {
return R.ifElse(
R....
0
votes
1answer
85 views
Haskell from float to Double
I've been trying to learn haskell for a couple days but I can't see to figure out how to create an answer/output that is a float, to a double
module SpaceAge ( Planet(..), ageOn) where
-- calculate ...
1
vote
2answers
53 views
Practicing on matrix - Ocaml
I am practicing on matrix at the moment but I am not really sure on the most efficient way to resolve some of the problems I encounter.
My first "problem" is to optimize a function. What I try to do ...
0
votes
0answers
49 views
Printing function definition in Scala
I have a sequence of functions
scala> a.foreach(println)
<function1>
<function1>
<function1>
<function1>
<function1>
It sounds impossible but I wonder if scala ...
1
vote
1answer
38 views
Hidden remote function call of a local binding in ocaml
Given the following example for generating a lazy list number sequence:
type 'a lazy_list = Node of 'a * (unit -> 'a lazy_list);;
let make =
let rec gen i =
Node(i, fun() -> gen (...
0
votes
1answer
35 views
call each value of an object pointfree
I've an object of functions:
const src = {
foo: str => str.toUpperCase(),
bar: str => str + str,
baz: str => str.split(''),
}
And I want to map the object to call each value with a ...
-2
votes
3answers
25 views
Mapping array elements to object values in JavaScript
As an example, using a few lines filled with capital letters:
input
.split('|')
.map(line => line.split(''))
.map(letter => ({
'Y': [0, 1],
'Z': [0, -1],
'X': [-1, 0],
...
0
votes
1answer
24 views
A function of type: ('a -> ('b -> 'c)) -> ('a -> 'b) -> ('a -> 'c) in Standard ML
Whilst revising for my programming languages exam, there are a few type inference questions for the Standard ML section, I can do most of them by doing type inference in my head, and I'm quite good at ...
0
votes
1answer
37 views
what does the law of mapping mean?(Functional programing in Scala)
On page 111, the mapping law reasons like below:
Line1: map(unit(x))(f) == unit(f(x))
Line2: map(unit(x))(id) == unit(id(x))
Line3: map(unit(x))(id) == unit(x)
Line4: map(y)(id) == y
What confuses ...
0
votes
1answer
31 views
Trouble with using modules with makefile (Ocaml)
I'm having a problem using my modules in my test file. I've created a simpler version here that still replicates the problem.
(* person.ml *)
module Person = struct
type person = {name: string; ...
1
vote
0answers
24 views
R programming functions
I'm learning R programming. I'm unable to understand how function within function works in R. Example:
f <- function(y) {
function() { y }
}
f()
f(2)()
I'm not able to understand why $f() ...
-1
votes
2answers
22 views
Best practise in format for npm module
I am creating a npm module that will take in some data from a js array of objects and allow the end user using the module to filter out only the relevant parts of data.
Im currently in the early ...
1
vote
1answer
16 views
Keep tracking “original” item in RxJs
I need to access the "original" value of stream.
My use case:
Iterating list of URLs.
Request each URL.
handle the response, and at this point, I also need the URL from the first "iteration".
...
1
vote
1answer
30 views
Unbound module Yojson.Basic.Util
I try opening Yojson.Basic.Util in one of my files and keep getting an unbound module error. I've tried several different things and can't seem to figure out what's wrong
I have this in my .ocamlinit:...
1
vote
1answer
31 views
How to import a module to use within a module (ocaml)
I'm new to functional programming and was wondering what would be the best way to do this. I have one file (display.ml) that has functions that saves, loads, and displays the high score, and another ...
-1
votes
1answer
27 views
mapping a generator to a list
I have a generator function that I want to apply to every item in a list.
Doing a
map(foo,var_list) , gets me a result like :
[<generator object window at 0x7f20720b1050>, <generator object ...
-4
votes
1answer
24 views
JavaScript & HTML | How to do Ingame Production Software? [closed]
I need help on my Project. I will do Ingame Production software with using HTML and JavaScript (optional PHP). I wanna to do eg: Online Gem Mining Game > Mining > Mine Coal (2 coals Per Second) > ...
8
votes
3answers
203 views
Is there a way to do conditional assignment to constants in Swift?
I would like to create an immutable value that is assigned different values depending on a condition. In Scala I would be able to write the following:
let attribs = if #available(iOS 8.2, *) {
...
1
vote
1answer
40 views
How to convert scala function as parameter in c++?
So I would like to implement functional programming in c++, just as it would be done in scala.
So lets say I have this code snippet in scala:
def exampleA(l: List[P], f: P => Option[P]): Option[P]...
1
vote
2answers
101 views
Converting Imperative to Functional style paradigm using Ramdajs
The following script create an object filtering some input data.
It is coded in a declarative way using several nested forEach.
I would like to know which API to use in rewritting this code using ...
0
votes
2answers
41 views
Ocaml refs not retaining its value
(* junk.ml *)
let flag = ref false
let get_flag = !flag
let play_cards card =
Printf.printf "%s-clause\n" (if card >= 27 && card <= 39 then "true" else "false");
(flag := if ...
-8
votes
0answers
41 views
Translate scala to C++ [closed]
I am wondering how i would be able to translate the following scala code into c++?
type Pos = (Int, Int) // a position on a chessboard
type Path = List[Pos] // a path...a list of positions
import ...
8
votes
2answers
236 views
Translate a Scala Type example to Haskell
I found a really interesting example in a Scala article and I am wondering how it might be encoded in Haskell.
trait Status
trait Open extends Status
trait Closed extends Status
trait Door[S <: ...
1
vote
2answers
26 views
Ramda - find like function but returning non falsy result of predicate instead of found value
Is there any function in ramda which works like find, but instead of found element returns the result of predicate function?
So for example R.find(x => x === 2 ? 'two' : false, [1, 2, 3]) would ...
2
votes
1answer
26 views
Is there some function to combine multiple sequences over a function? [duplicate]
If I have two sequences
(let [v1 '(1 2 3 4)
v2 '(2 4 6 8)]
...)
is there some way of combining them through a function to single vector, something like:
(combine #(* % %2) [1 2 3 4] [2 4 6 ...
0
votes
1answer
43 views
Scala functional programming operator :::
First i have type declaration for binary tree:
sealed trait BT[+A]
case object Empty extends BT[Nothing]
case class Node[+A](elem:A, left:BT[A], right:BT[A]) extends BT[A];;
And further i have this ...