What is (->) in Haskell?

If you type :i (->) in GHCi and hit Enter it returns the following: data (->) t1 t2 — Defined in ‘GHC.Prim’ infixr 0 `(->)` instance Monad ((->) r) – Defined in ‘GHC.Base’ instance Functor ((->) r) – Defined in ‘GHC.Base’ instance Applicative ((->) a) – Defined in ‘GHC.Base’ instance Monoid b => Monoid (a -> b) – Defined… Read More What is (->) in Haskell?

C+ selective predefined functor initializaiton

Predefined functors need to be in-place instantiated (with empty parentheses) for use in algorithms but not as type parameters for container adapters such as priority_queue. Why the difference? #include <queue> #include <vector> #include <numeric> int main(){ std::priority_queue<int, std::vector<int>, // parentheses are NOT neded here: std::greater<> std::greater<>> pq; pq.push(1); pq.push(2); pq.push(3); std::vector<int> v = {1, 2,… Read More C+ selective predefined functor initializaiton

save result of for_each algorithm inside a vector

I have a functor and the overloaded operator() of it returns a double. In an easy way I can write: int main(){ auto f=[](double t){return 1.0/(pow(7.0*t,2.0)+1.0);}; std::vector<double> nodes(n); bestpolchevnod(f,nodes); //calculate nodes = f_i(cheby_point(i)) ChebyPoly c_p = ChebyPoly(nodes);//call the constructor with the calculated nodes std::cout << c_p(0.6) << std::endl; //evaluate at c_p(0.6) as an approx of… Read More save result of for_each algorithm inside a vector