Hello,
Given a list of numbers, say, (1 3 6 10 0), how do you compute differences (xi - xi-1), provided that you have x-1 = 0 ?
(the result in this example should be (1 2 3 4 -10))
I've found this solution to be correct:
(define (pairwise-2 f init l)
(first
(foldl
(λ (x acc-data)
(let ([result-list (first acc-data)]
...
I am having a bit of a problem with a functor (and it's resultant type). Below, I have a Set functor that uses an Ordered type. I actually used the set.ml that comes with ocaml for some guidance, but I seem to be doing everything ahhem right. I created an Ordered module with integers and applied it to the Set functor to get the last modu...
To take an example, consider a set of discounts available to a supermarket shopper.
We could define these rules as data in some standard fashion (lists of qualifying items, applicable dates, coupon codes) and write generic code to handle these. Or, we could write each as a chunk of code, which checks for the appropriate things given th...
Recently I've been learning Lua and I love how easy it is to write a function that returns a function. I know it's fairly easy in Perl as well, but I don't think I can do it in C without some heartache. How do you write a function generator in your favorite language?
So that it's easier to compare one language to another, please wri...
Some background about me, I work for a financial organsation, in a support job. Where we work 10-11 hrs a day in supporting applications, which doesn't require any new additional skill. But my work also demands me to spend 6-10 hrs of java (servlet/jsp) coding per week.
But after 9 yrs of experience, I feel passionate about programming ...
I have just finished reading Little Schemer.. Now I am planning on reading Purely Functional Data Structures.. but the notations in the book looks very complicated.. are there easier alternative to this book that talk about data structure in functional languages.. if not then what do I need to read before I can start on this book...
Th...
Can continuations be said to be monads? Are they a subset of monads or are they simply a way of implementing monads?
Edit: Or maybe I got it wrong and monads is a more abstract concept than continuations? (So I'm really comparing apples to oranges here)
...
Object-oriented design (OOD) combines data and its methods. This, as far as I can see, achieves two great things: it provides encapsulation (so I don't care what data there is, only how I get values I want) and semantics (it relates the data together with names, and its methods consistently use the data as originally intended).
So where...
While learning Haskell I had the feeling that the authors where not always telling me everything, so to truly understand it I would like to know the theory behind the type system, monads and concepts like that.
Most of these concepts come from Category Theory I heard, so what are some good books/websites on this topic and related topics...
This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:
foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
produces:
1.0 1
2.0 2
3.0 3
4.0 None
5.0 None
Q. Is there a way to use map or any other functional tools in ...
I am writing a cache gen-server for the company Use. I am wondering how to search an item from the list as I want the cost of the search for comparing various data structures in erlang like dict, orddict, List, tuples, tree, queue etc to use for cache program.
Example,
List = [{"A1",["ankit","sush", "Hover", "x4", "a3","nilesh","mike",...
How do you pronounce the word 'Tuple'?
...
I'm learning a bit about function programming, and I'm wondering:
1) If my ForEach extension method is pure? The way I'm calling it seems violate the "don't mess with the object getting passed in", right?
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach ( var item in source )
action(item);
}...
What's wrong with the following little program that passes a function object?
#include <iostream>
#include <functional>
void foo(const std::unary_function<const std::string&, void>& fct) {
const std::string str = "test";
fct(str); // error
}
class MyFct : public std::unary_function<const std::string&, void> {
public:
void operat...
I've just recently discovered the functional programming style and I'm convinced that it will reduce development efforts, make code easier to read, make software more maintainable. However, I sucked at convincing anyone.
Well, recently I was given a chance to give a talk on how to reduce software development efforts, and I wanted to int...
Is there a way to print polymorphic values in Standard ML (SML/NJ specifically)? I have a polymorphic function that is not doing what I want and due to the abysmal state that is debugging in SML (see Any real world experience debugging a production functional program?), I would like to see what it is doing with some good-ol' print's. A...
When trying to use delegates in C# to solve a problem in a functional way, I've come across a pitfall that I want to share resp. for which I would like to hear your suggestions.
Background
I want to fill a grid from a list of objects where the values for single columns are get using delegates (idea borrowed from Philip Pipers ObjectLis...
I'm mapping an array of two-tuples from one domain (dates) to another (timestamps). Unfortunately, it looks like jQuery.map auto-flattens the two-tuples I return, and I don't see a do_not_flatten parameter.
Am I missing something else in the library that won't auto-flatten?
Addendum: I assume that I shouldn't be using Array.map, which ...
In the Integer module i tried to define the cmmdc opperation. the biggest common multiple. The problem is that i am doing something wrong cause the code does not work for 2 prime noumbers like 5 and 3.
this is my code for the Integer module:
module integer
{
protecting (natural)
[nat < int]
op s_ : int -> int
...
I have been doing object-oriented programming for a few years now, and I have not done much functional programming. I have an interest in flight simulators, and am curious about the functional programming aspect of Lisp. Flight simulators or any other real world simulator makes sense to me in an object-oriented paradigm.
Here are my qu...