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
0
votes
2 answers

filter max of N

Could it be possible to write in FFL a version of filter that stops filtering after the first negative match, i.e. the remaining items are assumed to be positive matches? more generally, a filter. Example: removeMaxOf1([1,2,3,4], value>=2) Expected…
Patrick Parker
  • 4,863
  • 4
  • 19
  • 51
0
votes
1 answer

Understanding the evaluation and execution order with semicolon syntax

I already learned a little bit about FFL semicolons from my previous question. However, it is still not clear what order of evaluation or execution they enforce. So here is a more concrete example: [ expr_a, expr_b ; expr_c, expr_d ; expr_e, expr_f…
Patrick Parker
  • 4,863
  • 4
  • 19
  • 51
0
votes
0 answers

Asynchronous Functional programming

I have a timer set for one minute and an asynchronous task already initiated (which will return a true or false). On timer expire, if the asynchronous task has returned and if it is true I want to show 'Success'. If the asynchronous task has…
Ambareesh B
  • 499
  • 1
  • 5
  • 14
0
votes
1 answer

Pure methods in c++/c# classes

So, I believe I understand pure functions. Something similar to abs or sqrt where the output is dependant on input and has no side effects. However I am confused about how this works with methods. If we view a method as a function with an implicit…
Programmdude
  • 551
  • 5
  • 22
0
votes
0 answers

Difference in how IO works in FP vs Non FP languages

Let's take the simple case here (pseudo code) def readnonfp(): String = { nonMonadicIO.readFile("somefile") } def readfp(): IO[String] = { monadicIO.readFile("somefile") } Now this will be maybe composed like…
ffff
  • 2,853
  • 1
  • 25
  • 44
0
votes
2 answers

Is it possible to represent Set as Tree in Haskell?

I'm reading Purely Functional Data Structres and trying to solve exercises they give in haskell. I've defined Tree in a standard way data Tree a = Empty | Node a (Tree a) (Tree a) I'd like to define Set as Tree where nodes are instance of Ord. Is…
user1685095
  • 5,787
  • 9
  • 51
  • 100
0
votes
1 answer

Purescript Eff Monad: using non-native computational effects

I want to be able to write x :: Eff (reader :: Reader Int, maybe :: Maybe) Int x = do config <- ask -- configuration from (Reader Int) monad just config -- using (Maybe) Monad runX :: Int runX = runPure (runMaybe doIfNothing (runReader 6 x)) --…
0
votes
1 answer

React Native Object.freeze not working

I'm attempting to freeze the keys inside my object so that I don't accidentally update them, as I'm using React Native (0.34.0) and Redux, so I need to use pure functions. However using the deepFreeze npm package, as well as trying…
Jonathan Lockley
  • 1,320
  • 5
  • 18
  • 28
0
votes
2 answers

What is a robust way of rendering a dynamic quantity of React child components, using the Redux container component pattern?

Say I have a functional React presentation component, like so: const Functional = (props) => { // do some stuff return (
// more HTML based on the props
); } Functional.propTypes = { prop1:…
pleasedesktop
  • 1,395
  • 3
  • 14
  • 25
0
votes
1 answer

Scala: Why this function is not tail recursive?

I have such implementation of Merge Sort: import scala.annotation.tailrec object MergeSort { def sortBy[T]: ((T, T) => Int) => Seq[T] => Seq[T] = comparator => seqToSort => { @tailrec def merge(xs : Seq[T], ys : Seq[T], accum : Seq[T] =…
0
votes
3 answers

How to make some asynch calls in a loop

In a loop i need to make some checks, performed actually in some another verticle. In each iteration of my loop i need to check the response code, returned from those verticle and make some decision accordingly. In some other words i need to stop…
user1053031
  • 727
  • 1
  • 11
  • 30
0
votes
2 answers

Running awk deterministic

I'm looking for a way to run awk in a verifiably deterministic way, that is to say: result should be determined by input only. In other words, given that a program has output, I want to know that it is repeatable. This would mean removing access to…
ateles
  • 422
  • 3
  • 10
0
votes
1 answer

What does 'pure' in functional programming mean if an application mutates the stack?

We know that pure functions: Always return the same result for a given input Produce no side-effects This leads us to referential transparency - where an expression can be replaced with a value without changing the behaviour of the program. This…
0
votes
1 answer

How to prevent cycles when using a purely functional depth-first search

I have a graph that is implemented as a list of edges connecting arbitrary nodes, with the data types defined below. type edge = int * int;; type graph = edge list;; How would I perform a purely functional depth-first search while avoiding getting…
0
votes
1 answer

Does it break composition to modify input in Haskell?

When I was reading the documentations of SDL in haskell, I found that some functions inevitably modifies its input. For example, blitSurface has destination surface as input, but it is updated within the function. Now, generalizing the problem, if I…
Carl Dong
  • 1,299
  • 15
  • 26