Questions tagged [combinators]
A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.
176
questions
0
votes
1
answer
55
views
Euler function of C(n, k)
Strange combination I know but here is my question:
We have 0 <= k <= n < 500000.
We need create an anlogithm that calculute Euler function of C(n, k) and not spend all your life for it)). ...
1
vote
1
answer
48
views
How C++ lambda move capture *this in rvalue reference member function?
we can move capture variable in c++ as follow.
string s;
auto f = [s = std::move(s)](){ /* do something */ };
we can copy capture this as follow.
auto f = [*this](){ /* do something */ };
but how ...
4
votes
1
answer
188
views
How to implement a fast type inference procedure for SKI combinators in Python?
How to implement a fast simple type inference procedure for SKI combinators in Python?
I am interested in 2 functions:
typable: returns true if a given SKI term has a type (I suppose it should work ...
3
votes
3
answers
149
views
How to implement SKI combinators in Prolog?
I want to implement SKI combinators in Prolog.
There are just 3 simple rules:
(I x) = x
((K x) y) = x
(S x y z) = (x z (y z))
I came up with the following code by using epilog:
term(s)
term(k)
term(...
4
votes
2
answers
116
views
Point-free version of g(f(x)(y))
Is there a way to express the following in point-free form:
g(f(x)(y))
It is not a common 'combinator' as far as I can see, though there are perhaps different ways to express it?
I am working in ...
0
votes
4
answers
192
views
foldl versus foldr for merge operator
Is the following statement equivalent?
foldr (++) [ ] = foldl (++) [ ]
I know that foldr (+) 0 = fold (+) 0 is equivalent and for the operator (-) it's not, but how about the (++) operator ?
I think ...
0
votes
1
answer
61
views
Creating something similar to a Zip or CombineLatest of IObservables that does not fire all outputs when one updates
See below the C# code for a Combinator that zips together two inputs
public class TransformScript
{
public IObservable<Tuple<bool,bool>> Process(IObservable<bool> source1, ...
0
votes
0
answers
239
views
Display hidden button in card when hovering
I would like to display the hidden button content in my card when hovering over it. I am currently attempting to use the adjacent sibling selector to do this, by connecting a hover element (the card) ...
1
vote
0
answers
144
views
Filtering multiple fields from a form to open a report
MS Access Database: I have a report that I want to open from a form with multiple filter fields. Each filter works fine when used individually. They do not work when I try combining them.
DoCmd....
0
votes
1
answer
74
views
Change Opacity of non-adjacent non-sibling non-parent div using CSS-Only Checkbox
I have an array of items. I want toggle their opacity or animate them. They're all objects in one div. I'd like to also change the opacity of the entire div and its contents with a toggle. On the same ...
0
votes
1
answer
349
views
Implementing SKI transformation
I need to implement the following algorithm in order to convert Lambda Calculus into Combinatory Logic.
The rules are from https://en.wikipedia.org/wiki/Combinatory_logic#Completeness_of_the_S-K_basis
...
0
votes
1
answer
38
views
How can I extract the redundancy in this Factor word definition with dataflow combinators?
I'm using the early ProjectEuler problems as a way to get to know Factor. Already in the very first problem I don't find a satisfactory solution.
I can solve the division test with this
: ...
0
votes
0
answers
23
views
Find out all combinations in a list but cannot be duplicated [duplicate]
I have a list: ['1','2','3','4']
I would like to find out all combination within the list but not allow duplicated values ("1|2"=="2|1")
Output:
1|1
1|2
1|3
1|4
2|2
2|3
2|4
3|3
3|4
...
0
votes
1
answer
257
views
Conditionally Acting on Specific Error Using and_then in Rust
How do I know what error happened when piping Results via and_then in Rust? For example using nested matches I could do this:
use std::num::ParseIntError;
fn get_num(n: u8) -> Result<u8, ...
0
votes
1
answer
172
views
Ultra-Hamiltonian cycle
Ultra-Hamiltonian cycling is defined to be a closed walk that visits every vertex exactly once, except for at most one vertex that visits more than once.
Question:- Prove that it is NP-hard to ...
1
vote
1
answer
286
views
Does SKS equal SKK?
Context
I started teaching myself lambda calculus last night and I am trying to determine if what I understand so far is correct.
Understanding
SKK is equivalent to the Identity combinator, I.
Where L ...
3
votes
1
answer
93
views
Can not understand 'pMany' and 'pMany1' in the parser combinator
I am trying to understand the pMany and pMany1 functions in the parser combinator
newtype Parser s t = P([s] -> [(t, [s])])
pMany, pMany1 :: Parser s a → Parser s [a]
pMany p =(:) <$> p <*...
0
votes
2
answers
427
views
Typescript: Typing a combinator for reducer-like functions
Consider the following types
type Reducer<S, A> = Red<S, A, A>
type Red<S, C, A> = (s: S) => (c: C) => A
and the following function
// The type intended for `reds` is
// `{...
7
votes
1
answer
3k
views
Rust chaining Results (Combinators)
I've been following a Rust tutorial where two versions of a function are purported to generate the same results:
Version 1:
pub fn get_transactions(fname:&str) -> Result<Vec<Transaction&...
2
votes
1
answer
171
views
Arrow law: first depends only on the first component of the pair. Why do we need this one?
John Hughes in his "Generalising Monads to Arrows" writes (chapter 8):
We formalise the property that first f depends only on first components of pairs as follows:
first f >>> arr ...
3
votes
1
answer
346
views
Y combinator in elisp
We can define a recursive function, factorial as an example, by YCombinator as follows
;;; elisp
;;; This code works. Thanks to
;;; https://www.diegoberrocal.com/blog/2015/10/12/y-combinator-in-emacs-...
1
vote
1
answer
161
views
Boolean SKI logic
I'm trying to grok the combinators, so I wrote the basic ones: K and S in Typescript:
const K: Kestrel = a => b => a;
const S: Starling = a => b => c => a(c)(b(c));
Then, I followed ...
2
votes
1
answer
111
views
What is this combinator?
I used a combinator to calculate the average of a list of numbers...
const myCombinator = f => g => h => x => f(g(x))(h(x));
I could then use it like...
const div = a => b => a/b;
...
0
votes
0
answers
41
views
collapse several rows into 1 comma separated field [duplicate]
I'm trying to take several rows and collapse the values in one column into a comma-separated list so that I end up with 1 row.
I have this:
SELECT tc.dv_task,
lob.sys_id
FROM task_ci tc
INNER JOIN ...
0
votes
1
answer
60
views
What is the best way to find and replace element in immutable set in Scala?
I have some immutable set of sets. Each set-element is a set of Ints, these Ints are unique.
For example, I have Set(Set(1,2,3),Set(4,5,6),Set(7)). I need to find an inner Set contains 3, and to ...
0
votes
2
answers
222
views
Evaluating SKI-combinators with not enough arguments
I was tasked with showing that
S(KK)I = K
Now since S takes three arguments, I was simply stuck at the beginning not knowing how to tackle this. I see two arguments, namely (KK) and I but there is ...
0
votes
1
answer
949
views
How to write css selector for selecting element before a given element [duplicate]
I have two elements inside a wrapper div. The second sibling in the view sometimes get an active class (as per the logic of UI)
<div id="wrapper">
<div>some content</div>
...
1
vote
1
answer
855
views
Finding permutations on 2D array
I have an 2D array like this.
1 2 3
2 3 4
Are there anyway to find all the combination that meet the requirement below ?
I want to find all the combination such as each number from a column must be ...
1
vote
2
answers
114
views
Haskell point-free style with no functions in the expression
I've been trying to take some simple functions and convert them to point-free style for practice.
I started with something like this:
zipSorted x y = (zip . sort) y $ sort x --zipSorted(x, y) = zip(...
9
votes
4
answers
836
views
How to use C# async/await as a stand-alone CPS transform
Note 1 : Here CPS stands for "continuation passing style"
I would be very interested in understanding how to hook into C# async machinery.
Basically as I understand C# async/await feature, the ...
0
votes
1
answer
141
views
Order of evaluation of Combinators in jsoup select
For example, if I write
* > a, b, c > d
Will the output tags be union of
* > a
* > b
* > c > d
OR union of
* > a > d
* > b > d
* > c > d
How do I get the ...
2
votes
1
answer
109
views
Composing web part continuations in Suave.IO with F#
Using Suave.IO, I have the following monolithic WebPart:
let success msg =
Successful.OK <| sprintf "Success: %s" msg
let error msg =
Successful.OK <| sprintf "Error: %s" msg
let ...
2
votes
2
answers
641
views
F# return list of list lengths
I am to use combinators and no for/while loops, recursion or defined library functions from F#'s List module, except constructors :: and []
Ideally I want to implement map
I am trying to write a ...
2
votes
2
answers
242
views
Getting the length of a list using combinators f#
let length (l : 'a list) =
let mutable counter = 0
for i in l do
counter <- counter + 1
counter
let list1 = [ 10; 25; 34; 45; 78 ]
length list1
I can get the length of a list using the ...
1
vote
2
answers
839
views
Generate all possible combinations with PHP
I have a sequence of numbers interspersed with underscore:
_10_1_18_4_9_14_ _
I would like to replace the underscore with letters without touching the numbers, and generate the complete list of ...
1
vote
1
answer
118
views
Check for bound variables fails for K combinator
I recently got in possession of a copy of "Essentials of Programming Languages", second edition. At page 29, the book introduces the following Scheme-flavored grammar for lambda calculus:
<...
4
votes
3
answers
727
views
Bird name for the (=<<) combinator?
The Haskell aviary combinators lists (=<<) as:
(a -> r -> b) -> (r -> a) -> r -> b
Is there an official bird-name for this? Or can it be derived via the pre-existing ones?
0
votes
2
answers
215
views
How can I make a combinator with this type signature?
I've been trying to make a combinator with this type signature:
(a -> b -> c) -> (c -> d -> e) -> a -> b -> d -> e
I've been through Data.Aviary.Birds and all the tacit ...
2
votes
2
answers
251
views
Conditionally using .reverse in the same line with Scala
I have a composition of combinators in Scala, and the last one is .top, which I could use as .top(num)(Ordering[(Int, Int)].reverse) depending on a boolean parameter.
How do I implement this ...
2
votes
2
answers
1k
views
Number of ways to pick at least x balls (balls are identical)?
There are N distinct boxes of balls in total. There are P boxes each containing A number of balls and remaining Q boxes contains B number of balls each.
Given a number X, what are the total the ...
4
votes
1
answer
405
views
How to handle 'line-continuation' using parser combinators
I'm trying to write a small parser using the Sprache parser combinator library. The parser should be able to parse lines ended with a single \ as insignificant white space.
Question
How can I create ...
2
votes
1
answer
646
views
Composing Option<Enum> with closures that pattern-match arguments
I have an enum with two different possible "types" and a function that may return any of them, wrapped in an Option:
enum Possibilities {
First(i32),
Second(String),
}
use Possibilities::*;
...
0
votes
1
answer
137
views
What does this mean in the Observable TC-39 proposal?
In the TC-39 Observable API proposal I see:
Compositional: Observables can be composed with higher-order combinators.
A combinator is a function that can be used to combine two (or more?) logic ...
2
votes
0
answers
820
views
Combining Imputed Datasets to make a single prediction — probability— for each example using a Classifier
I am working with a large dataset --300,000 records-- which has many missing values. So I used Imputation to fill the missing values and more specifically the Chained-Equations Multiple Imputation ...
0
votes
1
answer
704
views
implement boolean function using half adders and not gates
I received this question from my lecturer and i am stuck.
F=ca+b'a'
implement this function using no more than 3 H.A (half adder) and 3 NOT gates.
i succeed to get a'b' and ac
and still had 1 HA ...
0
votes
1
answer
87
views
Issue while using trycatch combinator in openwhisk
I am trying to use trycatch combinator in openwhisk and redirect to catch action in case I got error, but I am unable to redirect. Following is the sample code that I am trying with.
var openwhisk = ...
4
votes
2
answers
1k
views
Value getting dropped too early inside closure and combinator while borrow exists
I'm facing a problem with a value being dropped while it is still borrowed inside an Option, in a closure, but I'm having a hard time grasping exactly what's going on. To illustrate, here is a working ...
4
votes
3
answers
743
views
Combining two expressions into a pipeline
Let us say I have the following two expressions:
Expression<Func<T, IEnumerable<TNested>>> collectionSelector;
Expression<Func<IEnumerable<TNested>, TNested>> ...
0
votes
1
answer
54
views
length of the longest possible string contains no repeated 3-mers
I'm trying to find the length of the longest possible string of consecutive digits that contains no repeated 3-mers.
This is a bioinformatics question, and I'm sorting this for protein sequence.
...
13
votes
5
answers
3k
views
Practical use of K-combinator (Kestrel) in javascript
The K-combinator can be implemented as below and the implementation should not have any side-effects.
const K = x => y => x;
It is sometimes called "const" (as in Haskell). The K function ...