Questions tagged [purely-functional]

Purely Functional is a term in computer science used to describe algorithms, data structures, or programming languages that do not allow modification of data at run-time.

Purely Functional is a term in computer science used to describe algorithms, data structures, or programming languages that do not allow modification of data at run-time.

A pure function is a function whose returned value depends on nothing other than the arguments, and that causes no side effects; it contains no mutable hidden states. One consequence is that given the same arguments it will return the same value no matter when it is called, or how many times it is called, in the course of the program. In other words, such a function call (a "pure expression") has a value that does not depend on history or context.

Related concepts:

243 questions
1
vote
2 answers

Haskell: Change a list of 100 numbers to 10 lists of 10 numbers?

In Haskell, how does one change a list of x numbers into n lists of n numbers? The first sublist would have numbers first to tenth, second list 11th to 20th... myFunction :: [Int] -> [[Int]]
1
vote
3 answers

Pass a nested function as a parameter

Is there a way nest functions and pass them as a parameter? I have this 2 functions: function mayus(string) { return string.toUpperCase(); } function removeA(string) { return string.replace(/A/g, ""); } and I want to apply them in 2…
1
vote
0 answers

How to create back-edge in purely functional manner?

I am practicing purely functional style in C++. One big question is how can I construct tree data structure efficiently. Especially the back-edges. The connection to super-node. This can be thought as how to make a reference. In C++, people simply…
eonil
  • 83,476
  • 81
  • 317
  • 516
1
vote
1 answer

Is Functional Programming Similar to Self-Modifying Code?

It seems that sometimes code in functional programs accepts other code (functions) as arguments and modifies it and returns it for execution. It seems similar to self-modifying code. Does this mean that the compactness of functional programs result…
necromancer
  • 23,916
  • 22
  • 68
  • 115
1
vote
3 answers

Methods for side-effects in purely functional programming languages

At the moment I'm aware of the following methods to integrate side-effects into purely functional programming languages: effect systems continuations unique types monads Monads are often cited to be the most effective and most general way to do…
user141335
0
votes
1 answer

How to draw application functional diagrams?

I'm trying to find some good reads to clarify this but I'm unable to find it (or maybe I just don't know how to search this properly). What I'm trying to find is, considering that you have an application that: interacts with a db; interacts with…
Jack
  • 1
  • 1
0
votes
1 answer

How can I iterate properly through this list

The following example is a simplification of the problem. I have a list [Either Foo Bar],and another list [Biz]. The idea is that I iterate each Biz element through [Either Foo Bar] ,from the beginning of the [Either Foo Bar], until Biz is empty.…
user1198582
0
votes
0 answers

For an algebra of programming, is it better to use function-level programming or functional programming and why?

For his "Algebra of Programming" John Backus used the function-level style, which avoided lambda variables. Functional programming, on the other hand, uses Lambda variables. Does it matter whether you use lambda variables for an "Algebra of…
fpstefan
  • 1
  • 1
0
votes
1 answer

Purescript: How to read a string from stdin and save it?

I'm quite new to Purescript and I am trying to process some user input (received from stdin) but my best approach is this one: processInput :: String -> Effect Unit processInput input = do let arr = split (Pattern " ") input player1 =…
0
votes
2 answers

Using pure functions in a constant declaration

If I have this pure function: func PureFunction(x int) string { switch x { case 0: return "String zero" case 4: return "String four" default: return "Default string" } } and want to use it in a constant…
Kris10an
  • 548
  • 3
  • 23
0
votes
2 answers

Best Practices and Approaches while implementing pure functional Scala code which is dependent on impure code/libraries

I am currently Implementing business logic code which is dependent on the custom scala library which has a lot of impure functions and we have a lot of code with is dependent on this library and cannot refactor as it will affect others. So I am…
0
votes
0 answers

Append to an array inside an object functional way

Let's say I have an object like const team = { name: "something", members: [1, 2, 3], }; and in the above object I want to append the value 4 to the array? would this be acceptable code? const newTeam = { ...team, members:…
iJK
  • 4,655
  • 12
  • 63
  • 95
0
votes
1 answer

Exception handling and purity in Haskell

In The acquire-use-release cycle section from Real World Haskell, the type of bracket is shown: ghci> :type bracket bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c Now, from the description of bracket, I understand that an exception might…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

Functional implementation of recursive merge sort?

it has been several days of trying to implement a functional recursive merge sort in Python. Aside from that, I want to be able to print out each step of the sorting algorithm. Is there any way to make this Python code run in a functional-paradigm…
0
votes
0 answers

Reader for Dependency injection issue in Scala

In typical first example about using the reader monad for dependency injection we have: this like the classic https://github.com/hermannhueck/composing-functions/blob/master/src/main/scala/demo/Demo08bDbReader.scala Generally at the core of it is…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127