Hi all,
I have written some physics simulation code in C++ and parsing the input text files is a bottleneck of it. As one of the input parameters, the user has to specify a math function which will be evaluated many times at run-time. The C++ code has some pre-defined function classes for this (they are actually quite complex on the mat...
quoting from "The C++ Standard Library" by N M Jousttis, Section 5.9
#include < iostream>
#include < list>
#include < algorithm>
using namespace std;
//function object that adds the value with which it is initialized
class AddValue {
private:
int the Value; //the value to add
public:
//constructor initializes t...
Hi all,
I've been reading Alexandrescu's book, Modern C++ design , and I've been quite impressed by the techniques he uses, so I wanted to add Loki library to my application.
However, after further investigation, I saw that boost, that I'm already using, provides a lot of similar functionality (not all though, I couldn't find a singl...
I was having a look at the "Function" class documentation in Boost, and stumbled across this:
boost::function<float (int x, int y)> f;
I must admit this syntax is highly confusing for me. How can this be legal C++ ?
Is there any trick under the hood ? Is this syntax documented anywhere?
...
Learn You a Haskell has an example about functors. I can read LYAH, and text, and figure out what is supposed to happen -- but I don't know enough to write something like this. I'm finding this problem often in Haskell.
instance Functor (Either a) where
fmap f (Right x) = Right (f x)
fmap f (Left x) = Left x
However, I'm ...
Given the following member function overload to take various functors
class Foo {
public:
void bar(boost::function<void(int)> func);
void bar(boost::function<void(float)> func);
void bar(boost::function<void(const std::vector<float>&)> func);
}
and the function
void baz(float f) { std::cout << "float :" << f << st...
I'm a bit confused, and need someone to set me straight. Lets outline my current understanding:
Where E is an endofunctor, and A is some category:
E : A -> A.
Since all types and morphisms in Haskell are in the Hask category, is not any functor in Haskell also an endofunctor? F : Hask -> Hask.
I have a good feeling that I'm wrong, a...
Hello,
I'm developing some algorithms in OCaml which need some parts to be "pluggable" so that part of the computation is left to specific computators.
Just to make an example suppose I have a signature like this one:
module type Algorithm = sig
val feed : float -> unit
val nth : int -> (float -> float)
end
And two different ...
After reading (and skimming some sections of) Wadler's paper on monads, I decided to work through the paper more closely, defining functor and applicative instances for each of the monads he describes. Using the type synonym
type M a = State -> (a, State)
type State = Int
Wadler uses to define the state monad, I have the following (us...
Hello, I've the following situation:
module type M = sig type s = ... end
module Make(P: Something) : (M with type s = P.t) = struct
type s = P.t
...
end
that works fine to generate modules of M type that use specific implementation of modules of type Something inside their implementation.
Now suppose I have another module de...
What is the problem with this code ? this code is giving me lots of syntax errors. Also I would like to know why functors are used in C++.
class f
{
public:
int operator(int a) {return a;}
} obj;
int main()
{
cout << obj(0) << endl;
}
...
hey, i implemented the following functor:
struct CompareCatId : public std::binary_function<Vehicle*, Vehicle*, bool>
{
bool operator()(Vehicle* x, Vehicle* y) const
{
if(x->GetVehicleType() > y->GetVehicleType())
return true;
else if (x->GetVehicleType() == y->GetVehicleType() && x->GetLicenseNumb...
The key reason this works is that for_each () doesn’t actually assume
its third argument to be a function.
It simply assumes that its third
argument is something that can be
called with an appropriate argument. A
suitably defined object serves as well
as – and often better than – a
function. For example, it is easier to
...
The aim of the module described below is to implement a module which once initiated by an integer n does all the operations based on the value of n.
module ReturnSetZero =
functor ( Elt : int ) ->
struct
let rec sublist b e l =
match l with
[] -> failwith "sublist"
| h :: t ->
...