1
vote
1answer
69 views

GHC won't run this function, but does compile it

This is the code: finde_f x = if (x-2) mod 3 /= 0 then 1 else x - (x-2)/3 These are the errors during run-time: *Main> finde_f 6 <interactive>:170:1: No instance for ...
1
vote
1answer
75 views

Can the same fusion law for foldr be applied to foldlmap?

I've read there is no fusion law for foldl alone. If I guess correctly, this is due to foldl awkwardness for implementing map - which is mostly due to (foldl cons nil xs) reversing the list. If ...
4
votes
2answers
98 views

What are the properties of the unsided fold?

Foldl and folr are 2 very important functions for FP and Haskell, but I have never heard much about the unsided fold: fold f [a,b,c,d] = (f (f a b) (f c d)) That is, a fold that operates on binary ...
1
vote
2answers
87 views

Does Scala offer a way to “proxy” or “decorate” a function without repeating the argument list?

I have a class with the (admittedly stupid) name Application. There is also a class ApplicationRepository that features a private save(Application) method. I would like to add a method to ...
1
vote
1answer
45 views

Compute the inverse of function

I want to compute and plot the inverse of given function f. I have the following code in R : ############## Parameters ###### r1 <- 0.0125 r2 <- 0.0305 S1 <- 0.0400 S2 <- 0.0900 s1 ...
6
votes
1answer
90 views

applying a list to a function's arguments

How to write a function in F# for applying a list of values to a function like the Apply (@@) symbol in mathematica (map elements of the list to function arguments) for example apply f [1;2;3] calls ...
2
votes
4answers
113 views

Divisor function in clojure

I'm new to clojure and I want to create a function which returns a vector of all divisors of a certain Number. For instance: [1 2 3] for 6 as input (defn div [x seq] (let [r (range 1 (+ (/ x 2) ...
0
votes
2answers
31 views

Php save page id

What is a function that saves the page id? let me explain it for example I am in a lesson and want to save the current lesson,so when I came later to see where I left. Help me!
2
votes
2answers
109 views

What is a polymorphic lambda?

The concept of lambdas (anonymous functions) is very clear to me. And I'm aware of polymorphism in terms of classes, with runtime/dynamic dispatch used to call the appropriate method based on the ...
-1
votes
1answer
68 views

Ocaml “in” keyword and usage

I'm reading some notes and came across this code which looks quite clean for me: # let sigma f m = let rec sum (i, z) = if i = m then z else sum(i+1, z+.f i) in sum(0, 0.0);; val sigma : (int ...
6
votes
3answers
190 views

def or val for defining Function in Scala

I'm learning Programming Paradigms in my University and reading this course material provided by the lecturer that defined a function this way: val double = (x: Int) => 2 * x double: Int => Int ...
1
vote
1answer
56 views

OCaml function typing issue

I'm trying to write a Caml function and I'm having a few troubles with the typing. The function is : let new_game size count gens = let rec continueGame board = function 0 -> () |n ...
2
votes
2answers
115 views

Different brackets style on Scala function definition parameter list

What is the difference of the following two function definitions in Scala: 1) def sum(f: Int => Int)(a: Int, b: Int): Int = { <code removed> } 2) def sum(f: Int => Int, a: Int, b: Int): ...
-1
votes
3answers
35 views

how to pass params to a function that gets returned?

function callme() { //stuff return function($type = '%') use (&$data) { //stuff goes here return $data; }; } How can I pass a param to overwrite $type I just need ...
3
votes
2answers
224 views

Combining functions in Haskell

How can I combine these similar function in Haskell? getGroup [] acc = reverse acc getGroup ((Letter x):letfs) acc = getGroup letfs ((Letter x):acc) getGroup ((Group x):letfs) acc = getGroup letfs ...
4
votes
0answers
82 views

Are functions the only JavaScript objects with a “prototype” property? [duplicate]

[First this question may be taking about same concept as How does JavaScript .prototype work?, but is has different context.] I came across this blog which states: In JavaScript, each object has ...
2
votes
1answer
91 views

Scala compilers complains about “ambiguous reference to overloaded definition” when asking for a function in the second parameters set

This seems strange. The following will compile fine: def foo(s: String) = "balsh" def foo(s: String)(s2: String) = "kahsd" If I make the second parameter implicit, it still compiles fine and all. ...
1
vote
3answers
80 views

expose a function in go package

I would like to expose a function directly from a package. So I could call my package directly instead of mypackage.Somepublic() method. package main import ( "mypackage" "fmt" ) func ...
60
votes
2answers
2k views

What is “lifting” in Scala?

Sometimes when I read articles in the Scala ecosystem I read the term "lifting" / "lifted". Unfortunately, it is not explained what that exactly means. I did some research, and it seems that lifting ...
5
votes
3answers
80 views

how to assign functions to class fields in dart?

I understand how to assign a function to a variable in dart but how about a class field? Im currently doing it like this: class A{ DivElement rootElement; void addClass(String newClass){ ...
1
vote
2answers
248 views

How to use Function VB.NET Insert To Database?

i using function with vb.net. i'm query sql to datagridview and insert data from datagridview to Databse By function. But Error in function: The name 'EXHBK13004' is not permitted in this context. ...
1
vote
3answers
99 views

Can someone explain to me the difference between a Function Object and a Closure

By "Function Object", I mean an object of a class that is in some sense callable and can be treated in the language as a function. For example, in python: class FunctionFactory: def __init__ ...
2
votes
3answers
181 views

Haskell which function to group list every n such that :: [a] -> Int -> [[a]]

I'm sure there's a simple function to do this, it should: > groupEvery [1,2,3,4,5,6] 2 [[1,2],[3,4],[5,6]] I just don't know off hand and hoogle was no help..
3
votes
2answers
158 views

Writing an inverse function in javascript?

I ran into a situation at work today where I needed to write the inverse of a function that I had already written, but I found it inefficient to write the inverse manually because it seems like I ...
2
votes
3answers
134 views

haskell foldr and variable

How can I make a function similar to this but with n being a variable with a number beginning in 1 and ending with the value of the length of xs? For Example I want [1,2,3] to return the result of ...
4
votes
5answers
153 views

Clojure functions - returning value computed before the last statement

I have some tests written in clojure. This is a simple example: (defn test1 [] (start-server) (run-pvt-and-expect "PVT-0") (stop-server) ) I would like to return the result of ...
13
votes
2answers
497 views

Haskell Pattern Matching Fails on Negative Number

The Haskell compiler throws an error on the following function: balancedMax :: Int -> Int -> Int balancedMax -1 _ = -1 balancedMax _ -1 = -1 balancedMax a b = max a b Flipping the sign solves ...
4
votes
2answers
132 views

Why do these folds stop at the head/tail?

I'm reading learnyouahaskell.com and currently investigating folds. In the book there are these examples: maximum' :: (Ord a) => [a] -> a maximum' = foldr1 (\x acc -> if x > acc then x ...
0
votes
2answers
411 views

Understanding the apply method example in functional programming in Eloquent JavaScript

I am reading the Eloquent JavaScript and I got to Functional programming (chapter 6). I am confused by the following example: show(Math.min.apply(null, [5, 6])); function negate(func) { return ...
0
votes
6answers
143 views

Passing one subroutine to another subroutine

I have one function sub _where(\@ \&) which takes 2 arguments: the first is an array, and the second should be another function. This other function returns a boolean value, and I want to call it ...
0
votes
2answers
145 views

How can I define an operator (eg integrator) in Python operating on a multi-variable function?

How can I define an operator (eg integrator) in Python operating on a multi-variable function? My problem is that when I define an integrator function numint to numerically integrate a multivariable ...
0
votes
2answers
197 views

private functions vs nested functions

the question is: when to use private functions and when to use nested functions? (i'm asking about F# but maybe answers can be relevant in other functional languages) a small example namespace ...
0
votes
4answers
87 views

Converting this function to anonymous function

How do I create this function which returns true if a number is 5 to an anonymous function: def yeah_five(p: Int): Boolean = p == 5 thanks?
2
votes
3answers
237 views

What are those functional functions called?

I'm looking for a functional way to implement this: list = [a b c d e f] foo(list, 3) = [[a d] [b e] [c f]] A potential solution is: foo(list,spacing) = zip(goo(list,spacing)) Where, for ...
0
votes
2answers
163 views

Returning True for only 1 Function out of the list of 3

Since I'm pretty sure that using global variables in Haskell is frowned upon. I'm wondering is there anyway I can achieve the following? -- list has elements that are odd listHasOdd :: [Integer] ...
0
votes
2answers
87 views

Defining a variable within a function in OCaml

I've got a function numofday that I'd like to apply to two variables in another function that will return the number of days between the two given days, the functions themselves don't really matter, I ...
1
vote
1answer
74 views

Function to return a day n days ahead of given day

So I'm looking to build a function that takes an int and a day (of my day type below) and returns the day n days ahead of the given day. I have type day defined as type day = Sun | Mon | Tues | Wed ...
2
votes
4answers
246 views

Javascript: What is the benefit of using function context vs passing as parameter

Other than tricking existing functions that already implement this as something, why would you want to write a javascript function so that you need to alter its context (via .call or .apply) rather ...
1
vote
4answers
246 views

OCaml recursive function to apply a function n times

I want to create a function of type int -> ('a -> 'a) -> 'a -> 'a in OCaml that takes an int n (non-neg) and a function f 'a -> 'a and an argument a of type 'a. f should be called on a n times. I've ...
0
votes
1answer
64 views

Defining a function with a function as an argument

I am currently trying to define a function of type ('a -> 'a) -> 'a -> 'a which takes a function of type 'a -> 'a and an argument of type 'a and calls the function twice on the argument. I'm ...
2
votes
1answer
184 views

How to use lambda as lexical scope in C++

The codes are like this: int a = 1; auto f = [a] {return a;}; a = 100; std::cout << f() << endl; return 0; I expected to see 100 as the result. However, the a is like freezed when ...
0
votes
0answers
64 views

Which approach is better in terms of performance and code maintenance?

I have to call 2 functions inside another function and use their returned values in this function. I have provided a skeleton code below. This is not specific to any programming language, but you may ...
0
votes
2answers
166 views

Evaluate function from list in lisp

I need to write a function in lisp with two arguments - list of argumentless functions and list of integers. I need to evaluate functions from first list in order given by a second, i.e. (fun '(#'a ...
0
votes
1answer
75 views

Scheme - Passing too much arguments into a function doesn't cause error?

Given the following code : (define (g x y) (* x y)) (define (f x y z) (define (h x y)(g (+ x y) x z))h) Notice that I pass 3 arguments into g ,where g accepts only 2 . However ,no error ...
0
votes
1answer
136 views

Function passing blank list as argument instead of single-element list

I'm writing a function that parses strings into lists that get used by another function. One of the operations that it performs is that it attaches a character to a string inside the (sometimes deeply ...
5
votes
4answers
546 views

What object javascript function is bound to (what is its “this”)?

I know that inside the function it is this. var func = function { return this.f === arguments.callee; // => true, if bound to some object // => false, if is bound to null, because ...
-3
votes
1answer
90 views

Function that returns a function? [closed]

Q: Write a function make_cylinder_volume_func(r) which expects a number r to represent the radius of a cylinder. The function call make_cylinder_volume_func(r) should return a function which takes a ...
0
votes
3answers
201 views

Ruby method chaining - `tap` with replacement [duplicate]

Possible Duplicate: Is there a `pipe` equivalent in ruby? I'm looking at the tap method in Ruby - but unfortunately the object returned from the passed block is not passed on. What method ...
2
votes
1answer
153 views

Javascript object with a hidden function?

I want to create a variable such that foo.properties returns {default:{x:undefined}}. However, you may notice that the properties variable is not directly editable and thus __defineGetter__ is used to ...
3
votes
3answers
287 views

How to write a recursive function in C# that looks like A(key, B(key, C(key, ValFactory(key))))?

How do you write a function that has this form: A(key, B(key, C(key, ValFactory(key)))) Where A, B, and C have this signature: TResult GetOrAdd(string key, Func<string, TResult> generator); ...

15 30 50 per page