Skip to main content
Filter by
Sorted by
Tagged with
4 votes
0 answers
74 views

I am a professor teaching Haskell in a programming languages class. We are covering partial application and currying. So, I gave the following example functions: multThenAdd x y z = (x * y) + z ...
Tom's user avatar
  • 401
0 votes
0 answers
47 views

I'm trying to implement a helper function which partial apply arguments to a specific function and return a new function from typing import Any, Callable, TypeVar from typing_extensions import ...
luochen1990's user avatar
  • 3,905
3 votes
0 answers
65 views

What are the differences between the three syntaxes funName l = map fun l funName = \ l -> map fun l funName = map fun In general it does the same thing however in some cases it differs. The ...
Clément Morelle's user avatar
1 vote
1 answer
84 views

I'm trying to create a generic bind function for TypeScript that will apply a function with any number of parameters to a specific this value. Without types, the idea is simple: function bind(self, fn)...
John Gietzen's user avatar
  • 49.8k
1 vote
0 answers
72 views

So, I am currently doing an exercise where I have a list of employees, with the data type Employee. data Employee = Employee Name Age Salary deriving (Show) employees :: [Employee] employees = [ ...
Armin Haas's user avatar
0 votes
1 answer
65 views

I am working with a program that creates an array of data. The user should be able to use all entries or apply a filter. The filter function actually contains a lot of variables not directly related ...
Fuegon's user avatar
  • 121
0 votes
1 answer
113 views

Having a function taking two arguments: let yolo x y = x + y Is it possible to get information (or preferably, value) of one of the applied arguments after an application? Below is a pseudo-code ...
zajer's user avatar
  • 842
0 votes
5 answers
244 views

I am running into an error: Uncaught TypeError TypeError: multipliers.reduce(...) is not a function. I was looking at currying and partial application. I expected multiply function to correctly invoke ...
imparante's user avatar
  • 513
0 votes
0 answers
88 views

I am a newbie in Scala and am trying to understand partially applied functions. I can implement simple examples like when function takes two integers as input. But I wanted to combine variable number ...
Dhruv's user avatar
  • 597
0 votes
1 answer
116 views

I am wondering whether the following is possible in Scala: Given some vector x = (x_1, x_2, ..., x_n) in R^n and a function f that maps R^n to R, I would like to replicate this concept in Scala. The ...
kiyomi's user avatar
  • 131
1 vote
1 answer
503 views

I've encountered this problem with a few different major third-party libraries and frameworks now. Let me try to boil it down to the essentials: The API provides a class Example, where the ...
Karl Knechtel's user avatar
6 votes
3 answers
128 views

The following SML code is taken from a homework assignment from a course at University of Washington. (Specifically it is part of the code provided so that students could use it to complete Homework 3 ...
lamc's user avatar
  • 367
0 votes
1 answer
904 views

Usually when we use <input /> field in html, we get a callback function such as <input onChange = {(event) => console.log(event.target.value)} How is this event argument passed back to us? ...
programmerdev's user avatar
0 votes
1 answer
706 views

I'm practicing partial application of a function, that is, fixing function arguments. I've learned two ways to achieve it: By currying the original function first. By using .bind() method. In the ...
Emman's user avatar
  • 4,313
2 votes
2 answers
154 views

I want to write List.map (fun x -> x % 3) into a form like List.map ((%) 3). The issue with the latter is that it translates to List.map (fun x -> 3 % x) Not what I want. Is it possible to write ...
SAm's user avatar
  • 2,262
0 votes
0 answers
30 views

I was expecting Python's lambda to keep reference to value of local variables. So when I wrote: >>> ls = [ ... lambda: x*x ... for x in range(3) ... ] >>> [f() for f in ls] [...
Apiwat Chantawibul's user avatar
0 votes
1 answer
121 views

Precondition I have these definitions: def add(x,y): return (lambda x,y: x+y)(x,y) def call(f,x,y): return f(x,y) and these import aliases: from multiprocessing import Pool as P; from functools ...
Hm Renga Y's user avatar
1 vote
1 answer
144 views

Here's a JavaScript object, const obj = {a: [{ id: 1 }, {id: 1}, {id: 2}, {id: 3}], b: [{ id: 4 }, {id: 5}, {id: 5}, {id: 6}] }; and here's a code that correctly groups the items by .id in each of ...
Enlico's user avatar
  • 30.3k
4 votes
1 answer
2k views

Here's a 'compose' function which I need to improve: const compose = (fns) => (...args) => fns.reduceRight((args, fn) => [fn(...args)], args)[0]; Here's a practical implementation of one: ...
pokercatt's user avatar
3 votes
1 answer
98 views

In Learn you a Haskell, it is given the following example: map ($ 3) [(4+), (10*), (^2), sqrt] [7.0,30.0,9.0,1.7320508075688772] However, I don't understand why this works. The signatures of the ...
Our's user avatar
  • 1,055
1 vote
2 answers
216 views

TL DR: I am trying to create a function wrapper. The wrapped function takes no parameter but returns a value. The reason I want to do this is to create a function similar to "lock" but for a ...
Jul's user avatar
  • 73
0 votes
3 answers
107 views

Having read... How can I log key presses using turtle? I am trying to detect key presses using a slightly different method. Here is a simplified version of my code, which works as expected... from ...
Rich's user avatar
  • 27
0 votes
1 answer
366 views

I am looking for a way to group a set of partially applied functions with only the first parameter(s) being different. Or in other words; The group contains functions accepting any number of ...
Terry van Walen's user avatar
3 votes
2 answers
104 views

I known that r -> a is a Functor in a, and that fmap = (.) for it. This means that when I do fmap f g, with g :: r -> a, f is applied to the result of g as soon as the latter is fed with a value ...
Enlico's user avatar
  • 30.3k
1 vote
1 answer
230 views

I'm trying to write a function composition that partially applies an argument at each step and ends up calling a curried two-argument function. There is a set of example functions to compose. I ...
tssr's user avatar
  • 121
1 vote
2 answers
96 views

I would think that OCaml would read the following as an instance of partial application, and store the function as f. However, the compiler complains that the function is applied to too few arguments....
Addem's user avatar
  • 4,013
0 votes
0 answers
123 views

Just defined a generic map function in Swift: func map<T, S: Sequence>(_ f: @escaping (S.Element) -> T) -> (S) -> [T] { return { xs in xs.map(f) } } However, when I try to ...
F. Zer's user avatar
  • 1,311
3 votes
1 answer
170 views

I am just about to learn some typed functional programming, so just started with an implementation of partial application - which should be type safe. Problem: I am trying to make a function that ...
philipp's user avatar
  • 16.6k
1 vote
2 answers
481 views

How to change string to atoms using maplist. This does not work : ?- maplist(atom_string,["a","b","c"]). first because atom_string/2 has arity of two (How do you do ...
sten's user avatar
  • 7,546
3 votes
1 answer
718 views

I have written the following Haskell code to return the primary and secondary diagonal of [[Int]] getDiagonal' :: [[Int]] -> Int -> (Int -> Int) -> [Int] getDiagonal' [] _ _ = [] ...
mattematt's user avatar
  • 565
1 vote
1 answer
73 views

Given this function (btw, should I say it's defined by cases? How do I refer to functions defined like this?), f :: Int -> Int -> Int f 0 x = x f x _ = x I'm wandering what is the reason, if ...
Enlico's user avatar
  • 30.3k
0 votes
1 answer
221 views

I need similar @action detail routes on multiple ViewSets. I want to make sure they remain consistent. I don't want to put @action(methods=["post"], detail=True, url_path="something&...
Patrick's user avatar
  • 1,366
0 votes
1 answer
520 views

So I was writing (attempting) some variadic macros to try to implement compose and curry in rust. pipe was easy enough. Variadic partial application though? Not so much. Props to anyone who can come ...
Ross's user avatar
  • 19
1 vote
1 answer
1k views

How can I properly type the return type of the following function without using any? It's a function that, depending on the presence of one parameter, returns a string or a function. function ...
Julio García's user avatar
1 vote
1 answer
197 views

I was trying to do this let TryParseAnyNumberStyle = Int32.TryParse(style= NumberStyles.Any, privider=CultureInfo.CurrentCulture) But the compiler complains The member or object constructor '...
OrdinaryOrange's user avatar
2 votes
2 answers
595 views

I am having trouble with the right incantation to get a dynamic method added to a class using functools.partial in the following situation. The following has a Creator class to which I want to add a ...
HoosierDaddy's user avatar
2 votes
1 answer
116 views

In Type Synonyms we read Just like we can partially apply functions to get new functions, we can partially apply type parameters and get new type constructors from them. How can a parameter be ...
Enlico's user avatar
  • 30.3k
0 votes
1 answer
101 views

I have the following combinator that converts a mutli-argument function in one that can be partially applied: type Tuple = any[]; const partial = <A extends Tuple, B extends Tuple, C> (f: (.....
user avatar
0 votes
1 answer
136 views

I have three functions that I would like to refactor using currying but I am struggling get my head around functions that return functions. I am trying to break down and design the curried functions ...
tea's user avatar
  • 648
0 votes
1 answer
49 views

I've started playing with Akka and have found that most of my actors have part immutable state and part mutable state. Both could be merged into a State case class which could then be copied on solely ...
fishb6nes's user avatar
  • 124
2 votes
1 answer
243 views

Let's say I have a function int myfun (int arg1, int arg2, int arg3, int arg4) { /* function body */ } and I would like to write a function pass_last_elements() that has signature int (*)(int, ...
gosbi's user avatar
  • 846
7 votes
1 answer
190 views

I'm trying to understand something about Haskell functions. First, here is a Fibonacci function defined in the typical "slow" way (i.e. recursive with no memoization, and no infinite-list tricks) ...
cschatz's user avatar
  • 258
3 votes
1 answer
101 views

We can use purrr::partial to create partial functions: f <- function(x, y) { print(x) print(y) return(invisible()) } ff <- purrr::partial(f, y = 1) ff(2) #> [1] 2 #> [1] 1 Created ...
Wasabi's user avatar
  • 3,091
2 votes
3 answers
124 views

I have a side-effecting function, f : int -> string -> unit which I am calling using f 1 "hi". To make sure I get an error in the call site if the function is changed to need more arguments, I ...
Janus Troelsen's user avatar
3 votes
2 answers
340 views

I have a couple classes and a function: from functools import partial def fn(other, self, name): print(f"calling {name} with {other}") func = getattr(self.a, name) return func(other) ...
MBeale's user avatar
  • 750
3 votes
1 answer
160 views

I have these types: SomeTypeClass A higher kinded type which has one type parameter of kind * => * => * trait SomeTypeClass[P[_, _]] { def test[F[_], S, T, A, B](f: (A => F[B]) => S => ...
Sagi's user avatar
  • 9,364
0 votes
1 answer
194 views

given the following module the compiler raises an error 41 │ }; 42 │ 43 │ module TestB = { 44 │ let minFn = (a, b) => a < b ? a : b; . │ ... 54 │ let max = reduceList(maxFn); ...
hesxenon's user avatar
  • 520
1 vote
0 answers
102 views

I have the following code in F# live version at https://repl.it/repls/CarefulGiganticExtraction let inline tryParse text = let mutable r = Unchecked.defaultof<_> (^a : (static member ...
bradgonesurfing's user avatar
73 votes
3 answers
13k views

According to my understanding, partial functions are functions that we get by passing fewer parameters to a function than expected. For example, if this were directly valid in Python: >>> ...
Saurabh kukade's user avatar
5 votes
2 answers
1k views

I am looking for a way to partially apply functions in python that is simple to understand, readable, resusable and as little error prone to coder mistakes as possible. Most of all I want the style to ...
LudvigH's user avatar
  • 4,944

1
2 3 4 5 6