Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/Boost MPL: structure code likewise Haskell's let, where,

As C++ metaprogramming is functional: is there any way of doing something comparable to any functional programming language's (e.g. Haskell's) let or where construct?

I'm using Boost::MPL but would like to have more structure for longer metafunctions. Splitting into several functions is fine but I'd prefer let/where in some cases.

like image 972
user1034081 Avatar asked Jun 27 '12 08:06

user1034081


People also ask

How complex is the source code of Haskell?

The code is complex and shows a lot of the power of Haskell. The majority of the source code is comments rather than code. In addition, the code was written as clearly as possible rather than focusing on brevity. Hopefully, this will help the reader follow along.

Does Haskell use lazy evaluation?

First, Haskell uses lazy evaluation. For example, the following type is valid and Haskell will not complain about it: It is a polymorphic type, it has a single constructor 'AThing', and it is recursive. Values of this type will always be infinite if fully evaluated. That's okay, and you could use this in a program if you wanted to.

Should I use let or where in Haskell?

Haskell programmers often wonder whether to use let or where . This seems to be only a matter of taste in the sense of " Declaration vs. expression style ", however there is more to it. It is important to know that let ... in ... is an expression, that is, it can be written wherever expressions are allowed.

Is Haskell more powerful than C?

Haskell has both more flexibility and more control than most languages. Nothing that I know of beats C's control, but Haskell has everything C does unless you need to control specific bytes in memory. So I call Haskell powerful, rather than just 'good.'


1 Answers

The MPL itself doesn't support let clauses but some of the libraries built on top of it do. One example is metamonad. As the name suggests it also supports some other higher-level functional concepts (monads). A big drawback is, that metamonad is not an official part of the Boost distribution.

As far as work-arounds for the MPL go, splitting things into functions and using more namespaces to group them and then import the important symbol into your top-level namespace is probably your best choice.

like image 119
pmr Avatar answered Oct 12 '22 00:10

pmr