Tagged Questions

132
votes
4answers
10k views

What is the difference between a 'closure' and a 'lambda'?

Could someone explain? I understand the basic concepts behind them but I often see them used interchangeably and I get confused. And now that we're here, how do they differ from a regular function?
26
votes
14answers
3k views

What are some interesting uses of higher-order functions?

I'm currently doing a Functional Programming course and I'm quite amused by the concept of higher-order functions and functions as first class citizens. However, I can't yet think of many practically ...
24
votes
8answers
3k views

Uses for Haskell id function

Which are the uses for id function in Haskell?
19
votes
4answers
2k views

Haskell: How to compose `not` with a function of arbitrary arity?

When I have some function of type like f :: (Ord a) => a -> a -> Bool f a b = a > b I should like make function which wrap this function with not. e.g. make function like this g :: ...
18
votes
5answers
2k views

Why are “pure” functions called “pure”?

A pure function is one that has no side effects -- it cannot do any kind of I/O and it cannot modify the state of anything -- and it is referentially transparent -- when called multiple times with the ...
14
votes
4answers
515 views

In C, what is the difference between `&function` and `function` when passed as arguments?

For example: #include <stdio.h> typedef void (* proto_1)(); typedef void proto_2(); void my_function(int j){ printf("hello from function. I got %d.\n",j); } void call_arg_1(proto_1 arg){ ...
12
votes
3answers
2k views

OCaml: What is the different between `fun` and `function` keywords?

Sometimes I see code like let (alt : recognizer -> recognizer -> recognizer) = fun a b p -> union (a p) (b p) Or like: let hd = function Cons(x,xf) -> x | Nil -> raise ...
11
votes
7answers
304 views

can if be a proper function rather than a special form

I finally started learning functional languages (emacs lisp) and it makes explicit distinction between functions and special forms such as flow control , for example if. Is there a ...
10
votes
4answers
583 views

In Haskell, + is a function, (+ 2) is a function, (+ 2 3) is 5. What exactly is going on there?

How is this possible, what is going on there? Is there a name for this? What other languages have this same behavior? Any without the strong typing system?
9
votes
6answers
2k views

Haskell function composition

I am reading this tutorial on Haskell. They define function composition as the following: (.) :: (b->c) -> (a->b) -> (a->c) f . g = \ x -> f (g ...
9
votes
6answers
385 views

Is there a name for a function that takes a piece of data and a list of functions and applies each function to the result of the last one?

Clojure has a macro, ->, which takes a piece of data and a bunch of functions, applies the data to the first function, and then applies the result of that to the next one, the result of that to the ...
9
votes
1answer
133 views

Is it good practice for a Clojure record to implement IFn?

Suppose I have a record that is "function-like", at least in the sense that it represents an operation that could be applied to some arguments. I can make it work as a function by implementing ...
8
votes
2answers
816 views

When is a scala partial function not a partial function?

While creating a map of String to partial functions I ran into unexpected behavior. When I create a partial function as a map element it works fine. When I allocate to a val it invokes instead. ...
8
votes
1answer
1k views

compose function and functional module

Python 3.2 documentation refers to Collin Winter's functional module which contains function compose: The compose() function implements function composition. In other words, it returns a wrapper ...
7
votes
8answers
545 views

In which languages is function abstraction not primitive

In Haskell function type (->) is given, it's not an algebraic data type constructor and one cannot re-implement it to be identical to (->). So I wonder, what languages will allow me to write my ...

1 2 3 4 5 7
15 30 50 per page