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
1 answer

Equivalence relation in prolog

I would like to implement a simple if and only if relation in my Prolog code. Here is a simple example of what I would like to have: ?- a_iff_b(a, b). true. ?- a_iff_b(x, x). true. ?- a_iff_b(a, x). false. ?- a_iff_b(x, b). false. You get the…
bp99
  • 338
  • 3
  • 15
0
votes
2 answers

Purely functional stack implementation with scheme

I would like to implement a functional stack in scheme. This is my attempt: (define make-stack (letrec ((do-op (lambda (stack op . val) (cond ((eq? op 'push) (lambda (op . v) …
J. D.
  • 279
  • 1
  • 9
0
votes
1 answer

How to use |> operator with a function which expects two parameters?

kll : Float kll = let half x = x / 2 in List.sum (List.map half (List.map toFloat (List.range 1 10))) converting using |> can you also explain how to use the |> correctly with some examples cant find any…
y.west
  • 21
  • 4
0
votes
1 answer

Troubles when trying to "remove by index" on a Purely functional Linked List

As the title states, I have been trying to code singly linked lists and its operations on a purely functional implementation. Things where pretty breezy up until now, lots of recursion, no modification... the works. I then tried to implement a…
0
votes
4 answers

Functional Programming: How to convert an impure function to a pure function when the input needs to be mutated

How can I create a pure function that updates an object that's been initialized in another function something like: parentFunction = (inputs: object[], condtionList: string[]) => { const newObject = {f1: val1[], f2: val2[], f3: val3[]...} …
0
votes
2 answers

Haskell: use list generated in IO function in another, non-IO function

I am using a String -> IO [x] function in order to read in the contents of a file into a list where each element in the list is a word from the file. However, I would like to use the the [x] list as an input for another function. My issue is that I…
billbob
  • 41
  • 1
0
votes
1 answer

Why this snippet is not pure?

When I watch Google Chrome Developers, https://youtu.be/qaGjS7-qWzg?t=636 They said this snippet is not pure. I don't know why. const g = new Map(); for (const [u,v] of edges) { if (!g.has(u)) g.set(u, []); if (!g.has(v)) …
foxiris
  • 3,125
  • 32
  • 32
0
votes
0 answers

Is it possible for an application to be built by only pure functions?

As the title says, regarding a part of functional programming I have yet to see anyone discuss or answer areas of applications which isn't possible to write pure functions. I feel that it is indeed impossible to write applications with pure…
basickarl
  • 37,187
  • 64
  • 214
  • 335
0
votes
2 answers

Is this function pure? (Random computation, deterministic result)

A pure function is defined as a function that: Returns the same value for the same arguments, and Does not produce any side effects (mutation of non-local variables, I/O operations, etc.) Consider a function that calculates the greatest common…
0
votes
1 answer

Can a functional component be considered as pure if it has an internal mutable state?

Let's consider a functional component that has a mutable internal state: const FComponent = (options: any) => { let privateID = '0000'; return { ...{ // Public fields name: 'component' }, ...{…
0
votes
3 answers

Why purely functional languages allow passing parameters only by value?

I'm new to functional languages and I was wondering why we can't pass a parameter by reference. I found anserws saying that you are not supposed to change the state of objects once they have been created but I didn't quite get the idea.
0
votes
0 answers

Hamiltonian path functional way

I am trying to work on a problem which gives me a hamiltonian path in a graph. I am aware of the algorithms used for it but they're all suited for imperative style. My confusion is if I have to use dynamic programming in scala to solve the problem…
0
votes
1 answer

what is the relationship between safe & pure & referential transparency in functional programming?

pure / impure: appears when we talk about the different between Haskell and lisp-family. safe / unsafe: appears when we name functions like unsafePerformIO, unsafeCoerce. referential transparency / referential opacity: appears when we emphasize the…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
0
votes
2 answers

Parallel counting using a functional approach and immutable data structures?

I have heard and bought the argument that mutation and state is bad for concurrency. But I struggle to understand what the correct alternatives actually are? For example, when looking at the simplest of all tasks: counting, e.g. word counting in a…
0
votes
1 answer

Why functional languages use objects for data types?

I feel a tendency that most functional languages, like Kotlin and Scala, is handling all data types as objects. Double, Float, Long, Int.. They are all actual objects and they don't offer any primitive alternative? Why does functional languages…