Hi

After a couple of years using and keeping an eye on D I have grown into a functional oriented programmer. I began with JavaScripts semi pseudo functional style, then Clojures dynamic functional style, Haskells burritos and now Scala.

I have began to dislike Haskell for the academic approach to programming. To do anything you must think and think again. The knowledge you need to code haskell is more than the syntax and rules.

Then i thought about D some days ago. Thought Id give it a new try. Take a new look. See if something had changed from my side or the language. Well certainly from my side given the fact that I am no longer an OO programmer. Well i do OO stuff everyday, but despise it and remind myself and other devs how this could have be done better.

I found that there is std.algorithm, std.functional and lambda expressions in D. Thats very interesting. It gives a promise that I can use those tools to create (almost) class less programs. I initiated a vibe.d project and tried to change the listen handler to a lamdba expression:

listenHTTP(settings, (req, res) => res.writeBody("Hello, World!"));

And it worked obviously well.

But when I changed it to multiline lambda:

listenHTTP(settings, (req, res) => {
        res.writeBody("Hello, World!");
});

It gave me an error:

[jarl@galifrey vibed-app] $ dub
Target vibe-d 0.7.23 is up to date. Use --force to rebuild.
Building vibed-app ~master configuration "application", build type debug.
Compiling using dmd...
source/app.d(8,12): Error: None of the overloads of 'listenHTTP' are callable using argument types (HTTPServerSettings, void), candidates are:
../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(71,6):        
vibe.http.server.listenHTTP(HTTPServerSettings settings, void 
delegate(HTTPServerRequest req, HTTPServerResponse res) request_handler)
../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(95,6):        
vibe.http.server.listenHTTP(HTTPServerSettings settings, void 
function(HTTPServerRequest req, HTTPServerResponse res) request_handler)
../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(100,6):        
vibe.http.server.listenHTTP(HTTPServerSettings settings, 
HTTPServerRequestHandler request_handler)
FAIL .dub/build/application-debug-linux.posix-x86_64-dmd_2067-006B89616986857CBBFCCB1EAEA3E85E/ vibed-app executable
Error executing command run:
dmd failed with exit code 1.

Which I belive means that a single line lambda is a different object type than multiline lambda?

Why?

Reply via email to