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

Haskell: How to do a generic random function?

I am trying to make a generic function that returns a random value. I can make one working for floats, followed by another one working for ints... like this: randomFloat :: StdGen -> Float-> Float-> (Float, StdGen) randomFloat rndGen min max =…
0
votes
1 answer

Haskell Selective Text Obfuscation

I would like to obfuscate a text file report without obscuring certain keywords, like report titles, column headers, etc. I've built such a program using newLisp. I'm trying to implement the functionality in Haskell from scratch. Here is the code…
0
votes
2 answers

How is Scala suitable for Big Scalable Application

I am taking course Functional Programming Principles in Scala | Coursera on Scala. I fail to understand with immutability , so many functions and so much dependencies on recursion , how is Scala is really suitable for real world applications. I…
Avinash
  • 12,851
  • 32
  • 116
  • 186
0
votes
0 answers

Are there any conventions in F# for highlighting pure or impure functions?

Are there any conventions used in F# to highlight functions that are pure vs having side effects? I've seen that there is a Pure attribute in the Contracts namespace; but this looks to be a helper for CodeContracts. Do people even bother trying to…
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
0
votes
4 answers

Technical term for methods that mutate global state?

Is there a standard technical term for methods that mutate global state? "Unpure" is too strict, because the unpure methods println("I don't consider stdout to be part of the global state") and date() do not modify global state. "Mutator method"…
DaveFar
  • 7,078
  • 4
  • 50
  • 90
0
votes
2 answers

Abstract base class that defines a pure virtual function with a void* param. Derived class matching param is a pointer to some type

Revised, actual Base And Derived Class I am working with plus the function that instantiates it and uses the non virtual function call ShaderClass.h #ifndef SHADERCLASS_H #define SHADERCLASS_H #include #include…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

how to implement this deep copy in functional programming style?

Given the following structure: class G { Node[] nodes; } class Node { Node neighbour; } The deep copy operations can be defined as: function G copy (G g) { G r = new G(); Map isom = new Map(); for (Node node in g.nodes) { …
象嘉道
  • 3,657
  • 5
  • 33
  • 49
-1
votes
2 answers

Can the below function be called as pure function(JS)?

I was recently going through javascript pure functions. I found out that the pure function should not have any global dependencies, so according to this i encountered a doubt which i have try to explain below. function parent(){ const count =1; …
-1
votes
1 answer

implementing bubble sort with go

Please help me implement bubble sort.It works fine if I call it with a hardcoded slice from the main() but if I call it with dynamic input from Scan it breaks here is my code so far: package main import "fmt" func main() { fmt.Println("Enter a…
shouravRahman
  • 17
  • 1
  • 4
-1
votes
1 answer

Is there a way to write below piece of code in java 8 format?

I am writing a piece of code for creating partition key for a DDB table. I have long name in dotted format which can have as many names as possible seperated by "." e.g. qw.er.ty.ui I want the below method to return the subname of the above name as…
-1
votes
1 answer

Syntactical issue between order of two functions

Is there any order to be maintained while placing functions one another? I just tried the code on the online compiler provided by purescript.org itself "http://try.purescript.org" module Main where import Prelude import Data.List import Data.Array…
-1
votes
2 answers

Is fib(n) a pure function?

fib(n) calculates the nth fibonacci number: def fib(n): """Compute nth Fibonacci number""" pred, curr = 1, 0 # 0 is 0th Fibonacci number k = 0 # curr is kth Fibonacci number while k < n: pred, curr = curr,…
overexchange
  • 15,768
  • 30
  • 152
  • 347
-1
votes
1 answer

Itertools/functional approach to handling state over object?

My actual problem is much larger, but the gist of it is something like: def rec_func(it, newit, idx=0, seen_5=False, even_seen=0): num = next(it, None) if num is None: return newit elif num == 5: seen_5 = True elif num&1==0:…
A T
  • 13,008
  • 21
  • 97
  • 158
-1
votes
2 answers

Functional programming with clojure, avoiding mutable state

So, my question is about whether I can avoid mutable state in a particular action my program needs to do. Some context: About a week ago I decided to learn to program in Clojure, to teach myself functional programming. (By day I work as a web…
-1
votes
1 answer

How to ration amount in purely functional style

I need to distribute certain amounts to array of people according to their score. The rule is that their demands are met according to their position with whatever remains. In JavaScript using Lo-Dash (JSBin): var amount = 1000, people = [ {…
slobodan.blazeski
  • 1,040
  • 9
  • 20
1 2 3
16
17