« first day (1686 days earlier)      last day (3267 days later) » 

4:00 PM
Hmm.
 
I can swap all the thens to chains in the example and it'd be monads, the only difference is that then is accepted and it also takes non-boxed values.
 
@BenjaminGruenbaum I suppose you could really do this.Throw() (or similar) there? to illustrate it even more.
 
@BenjaminGruenbaum That was good, you should come and explain things here more often.
 
@BartekBanachewicz I have a throw there.
 
I don't get it.
 
4:01 PM
@Jefffrey well, that's just one example of using promises of "monads being useful".
Lots of others too.
 
@BenjaminGruenbaum you have a normal throw. We wanted to get rid of that, no?
I think it's a tad confusing
 
@Jefffrey it's hard to grasp, at first - play with it.
@BartekBanachewicz you can do return Promise.reject(Error(...))
Does the same thing.
 
I mean, what's the part that is not possible with exceptions again?
 
@Jefffrey all the functions in the thens are run on platform code, that is, at a later point - to illustrate:
 
@BenjaminGruenbaum yeah. You know, to firmly state that exceptions are not being used/mixed.
 
4:02 PM
Promise.resolve().then(function(){
    log(2);
});
log(1);

// logs 1, 2 and not 2, 1
 
You have a bunch of chained things. If one fail you deal with the exception in one place. With monads, if one fail you get the resulting error monad at the end.
Fell fairly equivalent to me.
 
@Jefffrey except the chained things are monads.
 
@Jefffrey Not if the thing is on separate thread
 
@Jefffrey yes, only exceptions were not expressive enough to use here since they're always synchronous.
 
@milleniumbug He said not to think about threads.
 
4:03 PM
monadic bind is used there. Have you not used it, you wouldn't be able to do that throw
 
Oh, that's an example of monads?
 
try {
    setTimeout(function(){
         throw new Error();
    });
} catch(e){
    console.log("This will never execute, ever");
}
log("This will run before the handler that throws");
@Jefffrey tricked you :D
 
Then what does throw mean in Javascript?
 
That's just because async is thrown in as low-level primitives and there's no language support
 
4:04 PM
Ok, let me show you how I would do that with exceptions.
 
@Jefffrey promises let you do throw and turn that into a Promise.reject, as bartek said to be more monadic you'd return Promise.reject(Error(...))
Ok, ping me when it's ready.
@CatPlusPlus JS has promises now, also async/await, also more primitives like observables on the way. but meh.
 
@Jefffrey well, it would be hard to show you how something is not done without them.
 
be back after dinner.
 
try {
    auto body = fetch("/api").get();
    function3(function2(function1(body)));
} catch (...) { ... }
 
58 mins ago, by Cat Plus Plus
You're both ridiculous nerds
 
4:06 PM
@Jefffrey that unwraps the promise and throws from synchronous code.
 
Assuming fetch to return a std::future<JSON>.
 
best thing I've read all day
 
@Jefffrey That's synchronous
 
I should head home anyway
 
@milleniumbug So function1, function2 and function3 you want to be executed asynchronously?
 
4:07 PM
@BenjaminGruenbaum I wish I was as good as you at explaining all that :(
@Jefffrey well, the key idea is that they are fmapped on fetch
 
How can they be executed asynchronously if they need the result of the previous calculation?
They look inherently synchronous to me.
 
@Jefffrey That's the thing
 
What is?
 
@Jefffrey function1,2,3 run when you get body- but you don't want wait in this try catch for that to happen
 
@Jefffrey >>=
 
4:09 PM
@Jefffrey Re-read this example - we read some stuff, then we plan to do some operations on the stuff we got, and send the answer to the web service.
 
@Jefffrey that's what you get when you fmap something synchronous on something unsynchronous
 
@melak47 Well, no. function1 runs always, function2 only when the result of function1 is returned and function3 only when both function1 and function2 are done.
 
Basically, it's a dialog between you and a web service.
 
Sean Parent said something really kind of enlightening - never call .get on a future, because in a single-threaded environment that is a deadlock.
 
user784668
@BartekBanachewicz I'm not from Poland you Bartek
4
 
4:11 PM
@BartekBanachewicz Ok, and how is a >>= b >>= c different from c(b(a)) here?
 
@Jefffrey not what I mean. you block on the .get(), so you just wait for stuff so you can continue. if you .then the stuff, you go on and that stuff executes whereever whenever
 
Xeo
@Jefffrey The latter needs the results immediately. The former may just pack more stuff into a future.
 
@Jefffrey With >>=, you don't call .get at all.
>>= on futures is .then()
 
@Xeo You can make c return std::future if you want.
 
@Fanael but you're a flower!
 
Xeo
4:13 PM
@Jefffrey That still means you need a and the result from b
 
7 mins ago, by Jefffrey
try {
    auto body = fetch("/api").get();
    function3(function2(function1(body)));
} catch (...) { ... }
 
a is an object in both cases.
 
user784668
@BartekBanachewicz Yes, which means I'm superior to you.
 
Xeo
Of course you can make those be futures too - but then you just hid the >>= part, really.
 
@Jefffrey just like c . b $ a is different to it
 
4:13 PM
Rewrite that as fetch("/api").then(function1).then(function2).then(function3);; that is how you want to do that.
 
@Fanael pwetty fwowew
 
And then translation to >>= is pretty literal.
 
@Xeo But that would still work.
 
Xeo
fetch >=> f1 >=> f2 >=> f3
Fishy pipeline! :D
 
@Xeo you then lift synchronous operations to asynchronous ones, I suppose
you can lift a pure function to a future
then the whole thing becomes ONE GIANT FUTURE
IOW Lounge learns monads other than Either.
 
4:16 PM
What does this have anything to do with exceptions?
I guess you can see std::future as a monad. But I don't see what's the point with regards to the whole discussion about monads being better than exceptions for errors.
 
@Jefffrey if you lift a normal function or fmap it on the future, you make all the exceptions from it to be thrown at some point when the future revolves. That means you can't catch them where you write that function. So you kinda attach the handler to the promise.
 
@BartekBanachewicz I think you'll kind of enjoy Sean's talk from this year's C++Now.
 
Ell
@Griwes its not always a deadlock is it?
 
user784668
@BartekBanachewicz Either way, maybe we should list all the IO functions?
 
@Ell In a single threaded environment (assuming no weird deferred launch policies) it pretty much always is.
(Single threaded as opposed to single core.)
 
Ell
4:18 PM
But in the default launch policy, it is executed immediately isn't it?
 
@Griwes Bartek++.
 
@Griwes videos available yet?
 
Ell
So by the time std::async is finished then the function has been executed and the future.. Filled?
 
We are of course not talking about the broken std::async thing that has nothing to do with asynchronous shit.
 
@BartekBanachewicz Well no. The point in which you need the future value you just call get() and you can catch the exception there.
 
user784668
4:18 PM
@BartekBanachewicz Is this a fork of Hell++?
 
Exceptions don't get out of std::future magically.
 
@Jefffrey more's the pitty
 
@Jefffrey there's no get being called.
 
@ScarletAmaranth Not yet.
@Jefffrey Don't call .get!
 
@BartekBanachewicz In what example?
 
4:19 PM
@Jefffrey Benjamin's
 
get breaks everything
 
23 mins ago, by Benjamin Gruenbaum
 fetch("/api").then(function(body){ // make async request
     return body.json();// async read the body as json
 }).then(function(json){
     if(!json.foo) throw Error("bar");
     return fetch("/someOtherApi?foo=" + json.foo);
 }).then(function(resp2){
     return resp2.body();
 }).then(function(final){
    console.log(final);
 });
 
Design your system so that the failure case there's an additional continuation attached.
 
"all the work you've done to build up to this" -> ruined
 
then calls get or something similar on the future no?
Otherwise I don't understand what then does.
 
4:20 PM
@Jefffrey It's >>=.
 
Ok, but you get the value of the future.
 
@Jefffrey It runs the function when the return value is available.
 
@Jefffrey you don't. The promise (the monad) does.
 
just how you can fmap
 
4:20 PM
That is Sean Parent's .then.
(Notice how he doesn't have that broken C++ promise thing that leads to bullshit like blocking futures.)
 
@Griwes is this pushing the offending exception to some handler in that composition chain?
Man, that looks like a huge hack
 
the next guy in the chain gets the value but you don't .get() it
 
Ok, the point of the example is that you are running a bunch of functions (one after the other) but their execution is not tied to the main flow. Right?
 
@Jefffrey kinda
 
@BartekBanachewicz What's not right about it?
 
user784668
4:22 PM
@melak47 I'd tell you a future joke but you wouldn't .get() it?
 
@BartekBanachewicz You have to push the offending exception to some handler in the composition chain.
 
how punny :p
 
You have to propagate it somehow.
 
@Griwes would be easier if there were no exceptions at all vOv
 
Also with that scheme, you are able to attach an error handler at any point.
Which is the same as with exceptions in regular code.
@BartekBanachewicz The world would be perfect if nothing ever broke.
 
4:23 PM
you can do that manually too
no i mean
 
@BartekBanachewicz The point is to have it done automatically.
 
you don't need exceptions here to get the same functionality
 
@BartekBanachewicz I know, I was trolling.
@BartekBanachewicz Sure, but it's kind of easier.
 
but you can't get that functionality with exceptions without monads //cc @Jefffrey
 
Especially with that little get_try thing at the bottom.
 
4:24 PM
@Griwes won't argue here.
 
Can you answer my question? /cc @BartekBanachewicz
 
Which actually throws an exception when there is one (...I think).
 
I am heading home. BB in hour or so
 
@Jefffrey Fine, it's right. What's next?
 
@milleniumbug I can't go forward unless we are clear that that's right.
 
4:25 PM
That is mostly it.
You put a function call out somewhere.
And you can say "after this happens, do this".
 
user784668
I think I gonna relicense something to HPND just for fun
 
You don't really care much about when that's gonna happen or where.
 
Question for you guys.
 
And you don't have to wait for anything.
 
You know, the trick it = v.erase(it);
Is there a way to pull it off in C++11?
 
Xeo
4:27 PM
huh
just do the same?
 
Ell
What is that trick?
 
erase takes a const_iterator but returns an iterator.
 
Xeo
so?
 
shouldn't iterator convert to const_iterator?
 
Xeo
^
 
4:28 PM
It does?
 
Xeo
yes
 
Is that another case of "MSVC sucks"?
 
user784668
@EtiennedeMartel Yes?
 
why wouldn't it?
 
user784668
@EtiennedeMartel Yes.
 
Xeo
4:28 PM
@EtiennedeMartel That shouldn't be
their iterators inherit from the const_iterators
 
@EtiennedeMartel no
 
@Griwes Then you can express that with std::async(blabla::actually_async, [a]() { try { function3(function2(function1(a))); } catch (...) {...} });
 
I can tell you for a fact that at least MSVC 2013 and 2015 convert it just fine
 
Oh, wait, it's another case of "my colleague doesn't explain his problem very well".
3
 
@EtiennedeMartel :v
 
4:29 PM
@Jefffrey No, you can't.
You'd need to call .get inside the callback.
This way you are polling.
Polling is almost always bad.
With continuations, they are notified about the readiness of the value in the future by the future itself.
 
@Griwes Why?
 
@Jefffrey Because otherwise you've gained nothing?
 
That stuff is going asynchronously and it doing the same exact job as the JS code.
 
You called .get, which blocked you...
...and then called async.
 
Never called get.
 
4:31 PM
...you have to call .get.
Otherwise you still have a future.
And not an actual value.
 
And then thread is running though.
 
Eh?
 
Sometime it will end and I will still have the future in my hand and never call get on it.
 
I am lost.
 
The thread that I've spawned with std::async (assuming proper flags and implementations) is running. It's executing the code inside the lambda. Independently from when I need the void value that I get at the end.
I could never call get on the resulting std::future<void> and the thread would still finish at some point.
 
4:33 PM
isn't this the "async is broken" gotcha? :v
 
Just like that fetch(...).then(...).then(...)....catch(...) will finish at some point.
 
i.e. calling std::async and not keeping the future automatically blocks on it for some silly reason?
 
@melak47 Wide will fix this
 
We are not focusing on C++ particular implementation. I'm just using that syntax because everybody seems to be familiar with it.
 
@Jefffrey I don't get what you don't get.
 
4:35 PM
@melak47 because otherwise you have a leaked thread that is randomly killed. I'm thrilled that feature exists
 
Okay, let's try this way.
 
anybody knowledgeable of linear logic?
 
@Griwes Do you know what you are supposed to do?
 
Your async (which, btw, is calling .get inside its callback!) has spawned a thread
 
Like, what's your goal in the discussion?
 
4:35 PM
and the spawned thread is now blocking.
Good job.
 
No, I'm serious. What's the goal of your discussion now?
What's your point?
 
7 mins ago, by Jefffrey
@Griwes Then you can express that with std::async(blabla::actually_async, [a]() { try { function3(function2(function1(a))); } catch (...) {...} });
Explaining to you that this is not correct.
 
Ok. I have spawned that thread that is executing.
And it's doing whatever function1/2/3 are doing.
I never call get on the resulting future (the one returned from async).
 
Okay, again. a is a future, right?
 
@TBohne how is the thread leaked? it does it's crap, and when it's done it can go kill itself. what's random about that
 
4:37 PM
No
 
a is a result of a .get call on a future?
 
a is any value function1 needs at the beginning.
 
Where did it come from?
Because we started from having a future.
 
It can even don't exist. It's a generic placeholder for arguments you want to pass to function1.
 
@melak47 int main() {std::async(real_async, [](){stuff();} } The thread is killed before it's finished.
 
4:38 PM
Oh wait, I see what you mean.
 
but we started out wanting to do function1,2,3 asynchronously after whatever async operation gave us that value...
 
33 mins ago, by Jefffrey
try {
    auto body = fetch("/api").get();
    function3(function2(function1(body)));
} catch (...) { ... }
Let's go back here.
 
Ell
How can I feed my indoor plant?
 
sacrifice a finger
 
Ok, I get what your point is.
 
4:39 PM
body is an effect of a blocking call to .get.
 
No, no. That example was for something else.
 
To get that value, you need to either 1) block with .get or 2) attach a continuation with .then.
 
@TBohne This will actually execute synchronously
 
@TBohne hmph :/
 
@Griwes and you actually never do .get anyway
 
4:40 PM
The future returned by async() blocks on destruction
 
@ScarletAmaranth Yes.
 
@AndyProwl he was using this to explain why it does :)
 
@AndyProwl Irrelevant; we are talking sane semantics. :D
 
holiday starts tonight
yay
 
Guys don't kill me, I just replied to one message and have no idea what you've been arguing about for the last two hours :D
 
4:41 PM
@Griwes Ok, so let me get this clear: fetch(...) returns a future of some value. Calling then(fn) on it, results in that function fn being executed when the future value is ready. And fn can also return a future, which can then be chained with another then and so on. Correct?
 
I just pointed out that "The thread is killed before it's finished." is incorrect
 
@Jefffrey Yes. .then itself returns a future, so you can always attach another continuation, but yes.
 
@AndyProwl I was explaining why that's a feature and not "broken async"
 
@Griwes Do we agree that we could implement it in C++?
 
(And when fn also returns a future you can see that .then is really a >>=.)
 
4:42 PM
@TBohne Yeah I realized sorry
 
@Jefffrey ...yes?
 
@Jefffrey it's like in parsec; if you bind an extra parser into the chain, you get back a parser; same with futures
 
With... wait for it... basically monads?
 
@Griwes And that exceptions would work just fine with proper handling?
 
@Jefffrey Depends on what you mean. :P
 
4:43 PM
Is Bartek wrong yet
 
@buttifulbuttefly I don't remember him every being right ^^
 
In the proposal for .then, the continuation takes a future, which is retarded, and was designed to handle errors (lol designing for the exceptional case, the committee is so bad).
 
The continuation takes a future?!
 
@TBohne Although I'm not sure it's a very useful feature: given a future, you don't know what you can and cannot do with it because depending on how you obtained it it has different behavior on destruction. I know the problem has been investigated and the decision was to keep the status quo, but it does not look like a great design
 
In a sane scheme, you can attach two kinds of continuations - one for actual values, and one for an error.
@Jefffrey Exception handling doesn't work "magically" with that; you have to implement it properly.
 
4:44 PM
@Griwes Well, actually it would have to, yes.
 
@buttifulbuttefly In the proposal, yes.
That's why it's borken.
 
Otherwise how would you pass an exception between one function to the other.
 
@Griwes do they even lift?
 
I think the continuation can take both a future and a value
 
What kind of Herb did they smoke
 
4:44 PM
@Jefffrey No.
 
don't remember the details
 
@ScarletAmaranth yes, at least they do
@buttifulbuttefly sutter
 
@Griwes Ok, saying "No." is cool and all. Can you please also attach something to it, so that we can keep the discussion alive? Come on.
It's not that hard to understand that "No." is a discussion killer.
 
@Jefffrey ...I am replying, it just takes time...
 
@Jefffrey It doesn't, then does it for you
 
4:45 PM
@Griwes No, I mean. Can you put in the same message?
 
@Jefffrey It's Robot style :P
 
Yes, I know it's in vogue right now.
It's terrible, hth.
 
It does make some sense
incremental information
 
Looking into JS further - most future libs I've seen have .then and .error (or .catch) on their futures.
 
you get the answer first, then the explanation
 
4:46 PM
@AndyProwl It's designed to piss your "opponent" off. That's it.
 
so you don't have to wait until he types a paragraph to know what the answer is
 
.then is only called on success from the preceding parts of the continuation chain.
 
you sometimes get a corny insult first tho
"Are you retarded?"
 
.error is only called on error.
 
Because ermgherd look how solid this NO. is.
 
4:46 PM
and then comes the explanation
 
Look at it.
I'm so solid.
 
@Jefffrey No.
 
This way you don't have to rethrow all the time.
 
lol
 
That's a nice one from Vlad:
@πάντα ῥεῖ Are you saying about me? No, nobody suggests a job. — Vlad from Moscow 1 min ago
 
4:47 PM
@Griwes oh no; almost as though these behaved like monads!
 
@Jefffrey Maybe that's the end result, not sure about it being "designed" to achieve that effect but yes, I also find it hurtful sometimes. However, logically it does make sense. It's like when you load an image and first you get it with crappy resolution, then with higher ones.
 
See, with a continuation taking .then, to propagate to the proper error handling routine, you have to rethrow the exception in every handler in the chain.
 
You don't have to wait too long to see something
 
@Griwes Oh right. That's even easier.
Yes, it could totally be implemented with exceptions.
 
Exceptions could have been implemented with exceptions.
 
4:48 PM
@milleniumbug now we know the true identity of captain obvious
 
@Jefffrey On both ends! (Both of the person writing futures and on the person using them!)
@ScarletAmaranth I see a monad in your future, man.
 
x86 doesn't throw exceptions (oh wait, it does - but they're different)
 
@Griwes Milchewicz (or however the fuck you spell his name) sure does
 
@Griwes So, this whole discussion and example is trying to show me how errors can be better expressed with error-like monads as opposed to exceptions. Do you believe that's the case?
Because if that's the case, then I don't see how this shows anything about monads to express error states.
 
4:49 PM
@Jefffrey Exception handling is monadic; I don't see how anyone could try to tell you that monads are better for error handling than monads.
(...C++ does have do-notation, it's just specific to one single kind of a monad. :D)
 
@πάνταῥεῖ lol
 
a >>= b >>= c propagates the error without intervetion (the >>= takes care of that); and so do exceptions
however, monads are a more general concept vOv
 
Yes.
 
3 hours ago, by Bartek Banachewicz
What I'm trying to show is that monads are strictly superior to exceptions
 
I believe that's exactly what I told.
@Jefffrey :DDD
 
4:51 PM
3 hours ago, by Bartek Banachewicz
Everything you can do with exceptions you can do with monads but not vice versa.
 
He is kind of right, you know.
 
In the context of error handling.
 
@Jefffrey they ARE; in different scenarios tho - as I said - Newton's physics isn't useless, even if it's not as general
 
Only not in the part where he misses that exceptions are monadic.
 
@Jefffrey this; right
 
4:52 PM
So that he is saying that you can do everything you can do with monads with monads.
:D /cc @BartekBanachewicz
 
@ScarletAmaranth What?
We were discussing stuff like Either or Maybe.
 
@Jefffrey in that context, they're isomorphic; you're right
 
@Mysticial Well, I didn't mean to start Vlad bashing again. But this one was just notable ;-)
 
In fact the whole discussion sparked from hash[key] returning nil instead of throwing an exception in Ruby.
2
 
:DDD
:D
 
4:53 PM
that's what you get for writing Ruby
3
I think you deserve it ^^
 
And I said that an exception should be thrown.
And Bartek said that Maybe a should be returned instead.
 
TIL about (nil)
 
Because monads are superior to exceptions.
 
@Griwes monads are for mad nomads ...
 
@Jefffrey If I were here at that point, I'd have said that they are the same thing.
 
4:53 PM
And I don't agree for that and similar cases.
 
As @ScarletAmaranth said, they are isomorphic; they represent the exact same thing.
Are monads superior than semicolons?
 
I think "superior" is a horrible word
just because something is a subset of somethign else, it doesn't mean it's inferior
Nats are a subset of Reals, it doesn't mean they're "inferior"
 
I was trolling.
 
(or that reals are superior)
 
Everything you can do with exceptions you can do with x86 instructions but not vice versa.
 
4:55 PM
everything you can do with monads you can do in brainfuck!
 
4 hours ago, by Bartek Banachewicz
@Jefffrey Monads are more flexible carrier of exception data that some implicit IO magic
This was the point where everything went down.
 
@Jefffrey Well, he's right about that one.
 
I still don't agree.
 
You had to write catch(...) in the function block.
That's less composable than .then(f1).then(f2).then(f3)
 
He kind of is, except he is missing the point that that some "implicit magic" IS MONADIC.
 
4:57 PM
@milleniumbug it's actually just as composable; denotational semantics breaks, but indirect denotational semantics can still be done
 
Also fuck I gotta go.
 
@ScarletAmaranth googles "denotational semantics"
...nope, still don't get it
 
3 hours ago, by Jefffrey
@BartekBanachewicz I would prefer exceptions, but I reckon they would be equivalent in that case.
 
So... you were right from the beginning.
lol
 

« first day (1686 days earlier)      last day (3267 days later) »