funq: syntax that doesn't scare off C++ developers

Aaron J. Seigo aseigo at kde.org
Fri Jul 25 13:21:25 UTC 2014


On Friday, July 25, 2014 14:36:09 Ivan Čukić wrote:
> > someFunction(a, b, c) when (a > 0)
> 
> Something like that could make sense. As I said in the previous mail, I'm
> trying to come up with a sintax that can be terse and expressive.

Ok; let's go with "when" .. I'll make the changes and push them to the repo in 
a few minutes.

> > there are many times when having multiple return types is very useful, of
> > course. if nothing else, it allows error objects to be treated as a normal
> > return value rather than an exceptional state like an exception.
> 
> You are right, though I'd rather have explicitly stated return types and
> errors - like Either(Real, ParsingError)

Hm... indeed. I'll have to ponder this some more ...

> > 	func() { a = 2; }
> 
> I'd propose then a keyword equivalent to 'auto' in C++, or 'let', or 'val'
> or whatever for definitions. (again, it would make parsing *much* easier -
> no ambiguities)

You've convinced me, esp due to the example you provided below :)

Of these options I prefer 'let' as it says exactly what it is doing and is 
shorter than "auto"; it's common in functional languages (as you know :) ... I 
don't think "auto" is quite so ingrained into C++ developer's minds yet, and 
other Algol/C-derivatives use different keywords for this (e.g. perl's 'my' and 
javascript's 'var') so we should have some wiggle room here.

> The problem would be is it
> (val x, y) = somePair // matches on y, extracts x
> val (x, y) = somePair // extracts both x and y
> (val x, val y) = somePair // extracts both x and y
> (x, y) = somePair // matches both

That actually seems completely sane to me right as it is. It does make 
extract-with-match clearer without having to read back into the function for 
context. No surprises, better chance for compile-time errors.

What does everyone else think?

-- 
Aaron J. Seigo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://kde.org/pipermail/funq-devel/attachments/20140725/66fe583e/attachment.sig>


More information about the Funq-devel mailing list