Posted: Mar 08, 2012 3:01 am
by mizvekov
VazScep wrote:Ah. Yeah. When you have to lug around 10Mb of runtime, you've got a non-starter there. Are things like tinyscheme workable?
Yes, I guess so, but I have not worked on a project yet where it would make sense.
Also, If I could use tinyscheme, I probably could use LUA, which has a more familiar syntax to those coming from imperative languages.

VazScep wrote:Ack. I worked with Scala for about a month and didn't enjoy a second of it. There's not enough type-inference for my tastes, I found it very verbose, and I think supporting null values is a big mistake (Tony Hoare calls his invention of the null value his "billion dollar mistake"). I'm much more hopeful about F#, which has made far fewer concessions to the OO world and looks far more like an ML dialect. The integration of type-inference into Visual Studio's intellisense makes it a joy to program with, and type inferred units of measure are just awesome.

I see, will keep that in mind next time I am up for learning it. Note however that none of this precludes it from having industry acceptance, there is far worse around :grin:

VazScep wrote:I've seen bits of the syntax for partial application with boost::lambda. It looked pretty line-noisy.

Yeah, but boost::lambda is pretty overkill for that, it's meant to provide lambda function support to c++98 compilers, and it is pretty hackish at that. No wonder it did not get accepted into c++11, and we got instead a proper lambda support which allows you to write their body just like any other function.
For partial function application, you could use boost::bind, which has been accepted into the standard as std::bind.
The syntax looks something like:
Code: Select all
        int b = 10;
        auto foo = [b](int a) -> int { return a + b; };
        auto bar = std::bind(foo, 1);
        std::cout << foo(2) << ' ' << bar() << std::endl;

This will print "12 11".
The example also shows the use of c++11 lambdas in the second line (declares a lambda which takes an int, returns an int, and captures variable b by value).
This also shows type inference with the repurposed "auto" keyword (it meant automatic allocation previously, as taken from C, but it was the default for every place which you could use it, so you never really had to use this keyword before, could leave it implicit).
The auto keyword is necessary in the lambda case because there is no way to express the type of a lambda which captures any variables. Lambdas that do not capture any variables are typed just like an ordinary function pointer.
Note also that std::bind can do parameter reordering as well.
Code: Select all
       auto foo = [](int a, int b) -> int { return a - b; };
       using namespace std::placeholders;
       auto bar = std::bind(foo, _2, _1); //Now you have foo with parameters reordered

By the way, do you have any recommended literature for Haskell beyond the beginner books?