Questions tagged [functional-programming]
Functional programming is a programming paradigm which primarily uses functions as means for building abstractions and expressing computations that comprise a computer program.
388 questions
0
votes
0
answers
38
views
Why [b] → Int < a → Int holds according to the contravariant manner for function types but length is a counter example for that
In the paper Practical type inference for arbitrary-rank types, the covariance and contravariance rules are essential when dealing with function types. Covariance applies to the return types of ...
4
votes
3
answers
622
views
Functor composition rule necessary?
Sorry if this is a dumb question, but I don't quite understand the composition rule for functors.I see how the identity rule makes sense, as mapping the functor over the id function shouldn't change ...
1
vote
1
answer
78
views
Is Calling a Function a Side Effect
I've noticed a pattern in trying to make functional programming effective - there is still some kind of impure, effectful operation going on, but it gets holed up in a single, manageable imperative ...
1
vote
1
answer
54
views
Understanding how lazy functional languages achieve IO (...sometimes?)
An Alternative view of I/O programs, popular in earlier lazy functional programming languages, was to see the input and output as Strings, that is as lists of characters. Under that model an I/O ...
0
votes
1
answer
109
views
Free variable in the programming language
From the wikipedia of Free variables and bound variables
In computer programming, the term free variable refers to variables used in a function that are neither local variables nor parameters of that ...
0
votes
1
answer
39
views
What are the non-overlapping properties of a function?
Specifically, properties that identify preconditions over which a function can be used without resulting in undefined behavior or data races.
For example, I am familiar with 3 important properties:
...
2
votes
1
answer
52
views
Is there any reference materials on complexity analysis for lazy languages?
Is there any books, papers or articles on how to analyze the time complexity of programs written in lazy languages such as Haskell?
I know how laziness is implemented and how it can be expanded and ...
1
vote
2
answers
70
views
(how) is assignment or binding possible in purely functional languages?
i can't seem to find much info on the following question:
how (if at all) is the fixing of names to values (by binding or assignment) possible in a purely functional system like the lambda calculus?
i'...
0
votes
0
answers
69
views
Representation of pairs in System F
System F defines the data type pair as:
$$X\times Y := \Pi Z. (X\to Y \to Z)\to Z$$
with:
$$\langle x,y \rangle := \Lambda Z. \lambda p^{X\to Y\to Z}.p \text{ }x\text{ } y$$
Projections are defined:
$$...
0
votes
1
answer
41
views
time complexity of loops
what is the time complexity of:
for (i = 1; i <= n; i = 2*i)
for (j = 0; j < i; j++)
sum++;
?
I thought it is O(nlogn) since the otter loop ...
-1
votes
1
answer
199
views
Call by value is known as pure function how ?give reason
I think call by value may be pure function or impure function...
And pure function can be written through call by value or call by reference....
So according to the facts (c) should be correct ans......
4
votes
1
answer
63
views
What is the object translating part of a monadic endofunctor?
A monad is an endofunctor $T:C\rightarrow C$ with natural transformations $\eta:id_C\rightarrow T$ and $\mu:T^2\rightarrow T$.
Being natural transformations mean that $$T(f)\circ \eta_A = \eta_B\circ ...
3
votes
2
answers
159
views
Does this esoteric representation of integers have decidable equality?
Consider the following datatypes in Haskell:
data Foo = Halt | Iter Foo
newtype BigInt = BigInt {nthBit :: Foo -> Bool}
Foo ...
2
votes
2
answers
196
views
Translation between unit/bind and map/join in monads
Is there a translation between unit/bind and fmap/join in monads?
https://stackoverflow.com/questions/34398239/with-monads-can-join-be-defined-in-terms-of-bind
gives a partial one:
bind f m = join (...
0
votes
1
answer
87
views
Is it possible for a language to have mixed evaluation strategies?
As far as I am aware, most functional programming languages today use a call-by-value eager evaluation strategy with some exceptions like Haskell. I am curious if it is possible for a language to have ...
0
votes
1
answer
71
views
What is lambda caculus's "fix point combinators" corresponding to Turing Machine?
The lambda caculus equals to Turing Machine,so What is lambda caculus's "fix point combinators" corresponding to Turing Machine?
according to the paper <Primitive Rec, Ackerman's Function,...
0
votes
1
answer
145
views
Compiler optimization pass joining identical function definitions together (or specializing them)
Consider this program transformation, in any direction, written in ANF:
...
1
vote
1
answer
46
views
Literature on delta encoding serializeable ADTs
Suppose that I have some nested algebraic data type (ie. something one can construct via datas in Haskell) that is serializeable (so no functional fields ...
0
votes
0
answers
24
views
What are the similarities and differences between dependent function application and ML functor application?
Advanced Topics in Types and Programming Languages gives this rule section 2.2 gives this rule for dependent function application:
$$\frac{\Gamma \vdash t_1 : (\Pi x : S.T) \quad \Gamma \vdash t_2 : ...
8
votes
1
answer
712
views
Strictness in both arguments but not in each individually
I'm learning about strict functions in Haskell.
A function f is strict if f ⊥ = ⊥
Some functions are strict only in the first argument (for e.g. const), others are strict in the second (for e.g. map)....
4
votes
1
answer
104
views
Book references for combinatory logic as applied in Haskell?
I am looking for book references on combinatory logic. Is there a book focused on how combinatory logic is applied in the context of pure functional languages like Haskell?
I found "Combinators: ...
2
votes
0
answers
60
views
Lambda calculus with unordered application
In lambda calculus, $\lambda xy.\phi$ isn't in general equivalent to $\lambda yx.\phi$. However, it seems possible to imagine a calculus which replaces application with something like specification, ...
2
votes
1
answer
68
views
Is there any formalization of GADTs implemented in OCaml?
There are papers that describe how generalized algebraic datatypes (GADTs) are encoded in core Haskell (System FC)[1][2], but I could not find any documentation on how OCaml formalizes/implements/...
0
votes
0
answers
38
views
Ambiguous type of "triangle" operator for sum types
In Meijer, Fokkinga and Patersons "Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire" the ∇ operator for sum types is introduced which removes the tags from its ...
0
votes
0
answers
37
views
Programming language implementation challenge: is recursion harder than HOFs, or vice versa?
(Initially this question was on cstheory, but I was told cs would be a better fit, so posting it here.)
All other things being equal, which of the following languages would be more challenging to ...
1
vote
2
answers
900
views
Does it make sense to call GAP a "procedural" language?
GAP is a computer algebra system (CAS) that Wikipedia tells me is written in C, a procedural programming language. Does this mean we can say GAP's language is procedural? Or is this characterization a ...
4
votes
1
answer
280
views
Is “x' = f(x)” a programming paradigm?
I'm the author of GateBoy (a gate-level simulation of the original Game Boy hardware) and Metron (a C++ to Verilog translation tool). One big issue I had to work around for both projects is the ...
0
votes
1
answer
83
views
Does category theory only deal with immutable objects? If so, why?
IIUC, category theory only applies to immutable objects, and mutability is modelled within that using e.g. functors, monads. Is that true? If so, why doesn't category theory include immutability? Has ...
0
votes
1
answer
76
views
Are there any formal systems or programming languages in which its only possible to define functions that have inverses?
Consider an algorithm $f(x)$.
Are there formal systems or programming languages that only allow $f(x)$ to be defined if $f^-1(x)$ exists?
0
votes
0
answers
60
views
Question about complexity of two topics in programming language theory
I am a student who is currently finishing second year of university mathematics. This summer I have to choose a topic for my diploma. Because I am particularly interested in computer science I am ...
-1
votes
2
answers
178
views
Are pure functions always computable functions?
Are pure functions always computable functions?
In computer programming, a Pure function is a function that has the following properties:
(1) the function return values are identical for identical ...
1
vote
2
answers
81
views
Can a strict right fold be implemented in a single loop?
A strict left fold is straightforward to implement as a loop, rather than with recursion:
...
3
votes
1
answer
167
views
Is possible to have a "pointer" to a tree node in a functional language?
Suppose I have the following structure definition in C:
struct node {
int value;
struct node *parent, *left, *right;
}
If I want to represent a specific ...
7
votes
1
answer
2k
views
What exactly is the relation between Haskell and category theory?
In articles or Quora posts about category theory, I often find mentions of the programming language Haskell. I have little knowledge of category theory and even less of programming. Could someone ...
0
votes
1
answer
28
views
How the indirect addressing works?
By other words, can anyone explain how indirect addressing works?
I red MARIE's LoadI X over and over and still didnt understand the logic behind it.
...
1
vote
1
answer
157
views
Proving transitivity in an intuitionistic type theory without the K rule
In Agda, if I disable axiom $\mathbb{K}$ I'm not able to prove
$$
\forall\{A : \textbf{Set}\}\{a\ b : A\}\{p\ q : a \equiv b\} \to p \equiv q,
$$
which I guess is normal since the system does not ...
2
votes
2
answers
86
views
What is the lower bound on retrieving an item in a collection if no arrays(Random access memory) are allowed?
I know that retrieving an item in a collection can be done in $O(1)$ time(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays....
2
votes
3
answers
102
views
To what extent is `this` state considered hidden-state - or its mutations a side-effect?
I was re-reviewing a somewhat upvoted answer of mine where I attempt to explain the differences between pure, impure, deterministic, non-deterministic, and idempotent functions.
In my answer I use ....
2
votes
1
answer
947
views
Addition in Lambda calculus
Found this term for a supposed 'adder' in lambda calculus.
λabcd.ac(bcd)
Although I know about alpha-conversion and beta-reduction and all that stuff, I don't know ...
0
votes
1
answer
127
views
Continuation passing transform
I'm stuck on something in in Shan's article Shift to Control, about CPS. On page three he writes the CPS transform
...
3
votes
1
answer
383
views
Why use the Y combinator for recursion?
The Y combinator is defined as $$Y=\lambda f.(\lambda x. f (x x))(\lambda x. f (x x))$$
It has the following useful property:
$$Y g = g (Y g)$$
for some expression $g$.
It can be easily used to ...
2
votes
1
answer
44
views
What is the meaning of "You describe the result you want rather than specifying the steps required to get there." in Functional Programming?
One of the characteristics of functional programming is as follows:
You’re describing the result you want rather than explicitly specifying the steps required to get there.
I found this quote at ...
10
votes
4
answers
4k
views
What are some interesting/important Programming Language Concepts I could teach myself in the coming semester?
I’m a CS senior with and Individual Study period this coming semester, and I’ve decided I’d like to learn more about Programming Language Concepts. More specifically, different programming paradigms, ...
1
vote
0
answers
98
views
Shallow Binding with static scope, is it possible?
I'm new in programming, I'm currently studying programming languages.
I'm trying to implement Shallow Binding with static scope, starting from an abstract syntax (producing a programming language ...
0
votes
1
answer
41
views
Pure Directed Graph
How can a directed graph be efficiently represented in a purely functional language like Haskell? Could someone suggest relevant materials on this topic? (functional pearls perhaps?) Thanks.
3
votes
2
answers
141
views
Semantics and implementation of side effects
From a practical point of view, how do functional languages with formally specified semantics (like ML) handle side effects like printing? I'm aware of things like the IO monad in Haskell but I'm ...
0
votes
0
answers
41
views
Question about machine learning
Hello everyone I am new to the site, I have a question that was in the test and did not understand the parts that are in the question. This question from a test I failed to pass, in a machine learning ...
8
votes
2
answers
166
views
Does the concept of "side-effect" predate functional programming?
When I was reviewing a book, I saw that there's a sentence claiming "side effect is a term coming from the domain of functional programming". I would think that the concept existed before ...
3
votes
2
answers
158
views
How, if possible, can we efficiently compute with lazy data structures in 𝜆-calculus?
In Haskell, we can use the following code to define fibonacci numbers,
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
And its time complexity is linear.
I cannot find ...
5
votes
2
answers
91
views
Is there one (or a few) canonical/ specific use cases for "functions returning functions" (beyond "decorators")?
Is there one (or a few) canonical/ specific use cases for "functions returning functions" (beyond "decorators")?
What can you do with "functions returning functions" ...