« first day (290 days earlier)      last day (171 days later) » 

17:20
Here I am
:21987631 It's better to transport your failure as a failure even if serialised, than it is to transport your failure as a success. The latter involves messing around with the failure handling machinery. You need to manually propagate failure. Your bind chains will not enjoy it. The former only interferes with handler code and it's just a simple handle s = let e = read s in handle' e.
1 message moved from Lounge<C++>
@R.MartinhoFernandes I think I could write a bind chain that wouldn't have problems with that additional Either
could you join those?
@BartekBanachewicz Yes, you could, but it doesn't scale because you have to do it everywhere.
well what if you join
I wish exceptions could be documented in the type system
17:23
@BartekBanachewicz Everywhere.
Or bartekJoin
come on!
@BartekBanachewicz You need bartekBind, not bartekJoin.
Either String (Either MyError a) ==ZIGAMORPH==>> Either (Either String MyError) a
@R.MartinhoFernandes well I need ==ZIGAMORPH==>>
no information lost, error pipeline a bit dirty but main data intact
just one wrapper
c'mon it's not that bad.
of course no idea if @Jefffrey doesn't need something way more complicated
@BartekBanachewicz That you have to use everywhere.
@R.MartinhoFernandes So, why did you say exceptions are bad?
17:25
@R.MartinhoFernandes I kinda got used to using such things in Hate. Most of my dos have wrappers, which are easily changable
once I change my structure, I don't have to change anything in the code typically
@BartekBanachewicz You got used to propagating failures as success?
@R.MartinhoFernandes no, to using wrappers
@BartekBanachewicz But not for this use case, right?
@Jefffrey (I'll get to that in a bit)
I figured
@BartekBanachewicz Are your wrapper thingies used something like wrap $ do { a; b }?
17:29
@R.MartinhoFernandes mhm
is that a monad?
MonadWrap :D
In wrap $ do { a; b } there's no proper propagation of the failure between a and b.
yeah well I really only meant the thing that you put in front of the do
you're taking it too far
It might be useful for other scenarios, but here it's just wrong.
@R.MartinhoFernandes mmm
17:41
@Jefffrey I have two objections to using exceptions in pure code, one ideological and one technical.
The ideological boils down to exceptions being a hack to let us write functions that are not total but masquerade as such (they kinda are: the language doesn't need them, but it would make the barrier to entry even higher; just one of the many design 'mistakes' that cater to newbies).
The technical one is the fact that the behaviour of code that uses exception-throwing pure functions is unpredictable because of lazy evaluation.
@R.MartinhoFernandes that
@R.MartinhoFernandes "let us write functions that are not total", you mean that for a "pure" function ƒ : A -> B it looks like for every element of A we get a B, but the truth is that an exception could be thrown and nothing could be returned?
(Note that my objections apply exclusively to code that doesn't make use of an error monad) (And yes, I know that my use of "pure" as a shortcut for "not-IO" doesn't match my view that IO code is pure :P)
@Jefffrey Yes. The textbook example is head.
@Jefffrey mhm
Well, I see your point and I simply disagree on that one.
17:44
@Jefffrey you think head is fine?
Fair enough. I said that one is ideological, anyway.
@R.MartinhoFernandes This one I never thought about.
It doesn't seem unpredictable though.
Consider ((head x) == 0) && y.
If x is [], what happens?
I have no idea because I don't remember the way they are grouped together.
I know function application beats every fixity.
Added parens.
17:47
What's y?
Bool
Some expression. It can be True or False. The False case is the problematic one.
It can either throw or be False depending on what gets evaluated.
The execution is stopped
@Jefffrey Not if head x == 0 is never evaluated, which is possible.
I see what you mean
I've heard they want to standardize the order of evaluation of function arguments in C++.
The left size is evaluated first in C++ of course.
C++'s && is short-circuiting on the left.
17:51
Due to short-circuiting.
Yeah, but you can use & for reasoning which doesn't short-circuit.
In that case it just throws because both get evaluated regardless.
What makes it messy in Haskell is that you can get short-circuiting on both sides.
And you can't have that and keep Haskell lazy evaluated.
Well, worse/better: you can get short-circuiting everywhere.
Interesting
Is that UB currently?
17:55
Yeah, ((head x) == 0) && y specifically
It's not exactly like undefined behaviour because there are only two valid outcomes.
It can only throw or be False, not order pizza.
lol
But it's not specified which one Haskell should evaluate that to?
No.
There's no guarantee that unnecessary code will not be evaluated.
Well, ok, but those a little corner cases though.
Such guarantee would be impossible to implement (proof by halting problem). If you ignore the cases that make it impossible, it would be impractical.
17:58
I don't think I've used exceptions once
@Jefffrey I don't think so
And in that case you can disambiguate what you want using seq or $! for example.
I think head :: [a] -> Maybe a is clearer and cleaner
it's perfectly obvious why it might not return an a and no such things can occur
The preconditions of head are fine as they are.
they're really not
@Jefffrey If you have many such "semi-pure" functions, it can easily get out of control. I picked a simple example for discussion purposes.
18:00
You can't use head as it is in a monadic context easily
@R.MartinhoFernandes Well, I think that exceptions are extremely valuable. In Haskell too.
@Jefffrey I don't.
@Jefffrey And if you're going to change the code that uses them anyway, you might as well change them to a monadic combinator.
@Jefffrey I think Haskell exceptions in non-IO code are only valuable for marking programmer errors (similar to std::logic_error).
I might agree that in IO context some standard way of "shit's broken" is in order
but in completely pure contexts they are terrible
there's no "exception" to be made in a pure context
In IO code they're useful to signal exogenous errors.
18:02
What I currently have are opaque types that have some invariants.
I mean, you're given data and you operate on it.
There's nothing exceptional that can happen
there's just data
They contain a string and only a small subset of all possible strings are valid.
@Jefffrey you need dependent types, not exceptions then
And with that I wholeheartedly agree
I defined a FromJSON instance for them, that throws if the subset passed is not correct.
Haskell needs dependent types
@Jefffrey mm, in that case
18:04
And it would be beautiful to just use a <- jsonData (parses the JSON data of the request body to the type of a)
Which defines the "successful" flow.
I don't think, again, that throwing is in order
@Jefffrey you seem to be missing the whole point of >>= used in errorful contexts
And then have a unique point of failure, in the API, where all exceptions are converted to some JSON object to be returned from the API in the response
you can build such machinery with monads
there's no need for obscure language feature to do that
If you don't like to use Monads then I don't get why you're using haskell at all
use dunno, Scala?
So you only have to think about 2 flows: the correct one, and the one when even just 1 thing broke.
I'm pretty sure you can throw in scala
@Jefffrey and that's different to chaing monadic computations how again
18:06
@Jefffrey But Parser does that already, no?
@R.MartinhoFernandes Does what?
Everything you described.
(You may have to write a <- parseJSON jsonData, I guess)
jsonData has a Scotty monad as type
Where every exceptions occurring are caught and converted to Text
So I never see Parser, except maybe in the instance declaration of FromJSON, for my types.
Oh.
I guess people suck at library design in every language.
Scotty is simplistic
18:09
In my specific case I know exceptions would work pretty great.
But I realize that in general they might be troublesome.
@Jefffrey if parser didn't use exceptions it would also work pretty great
because you can do pretty much everything you want without exceptions and then exceptions are never a problem.
@BartekBanachewicz In this case I can't
Because FromJSON has it's own return type.
That is fed into Scotty
that's a problem with Aeson too.
So the only way for me to use your monadic chains, is to rewrite one or both of those.
hardly a rewrite; just genericity on error type
18:12
No, no. A rewrite.
It's not the only way, but I get why you wouldn't want to do any of the alternatives.
At least of Scotty
Scotty already uses an ErrorT internally.
But they use it with their own error wrapper, that takes all errors and converts them to Text. And that's why your error has to be an instance of ScottyError: because they need to be able to convert to and from text.
I can see how that can be a problem
So you would have to define Show and Read for your errors.
Like robot said.
18:14
Or serialize them somehow.
I can see how that can be a problem too
or at least unnecessary complexity
yeah
I could make it work, but I feel like there's a much cleaner way I'm just not allowed to get.
And all of this without considering that Postgres.Simple also throws its own exceptions.
Which yeah, I guess I could catch in some IO and convert to Either or ErrorT.
But that's far from clean too.
JuicyPixels uses Either thank god
so pleasant to work with
image <- (fmap . fmap) JPU.fromDynamicImage $ JP.readImage path
I love that line
18:33
nice transcript guys

« first day (290 days earlier)      last day (171 days later) »