@DiazCarrete@hachyderm.io avatar

DiazCarrete

@DiazCarrete@hachyderm.io

This profile is from a federated server and may be incomplete. Browse more on the original instance.

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

In Servant, the ServerError type has an Exception instance
https://hackage.haskell.org/package/servant-server-0.20/docs/Servant-Server.html#t:ServerError
You might speculate that when throwing a ServerError using liftIO . throwIO in a Handler, the ServerError is automatically caught and served as a response, but it ain't so: it's treated as just another exception, and the response code is 500.

Instead, you should throw ServerErrors using "throwError", re-exported from the "Servant" module.
https://hackage.haskell.org/package/servant-server-0.20/docs/Servant.html#v:throwError

image/png

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

friendship ended with ScopedTypeVariables, TypeAbstractions is my new best friend
https://serokell.io/blog/ghc-dependent-types-in-haskell-3

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@BoydStephenSmithJr How do you un-pun your newtypes? Do you use some kind of "Mk-" prefix?

DiazCarrete, (edited ) to haskell
@DiazCarrete@hachyderm.io avatar

https://hackage.haskell.org/package/network-uri-2.6.4.2/docs/Network-URI.html#g:2
https://www.ietf.org/rfc/rfc2396.txt
https://webmasters.stackexchange.com/a/56844/89929

"A relative reference that begins with a single slash character is termed an absolute-path reference. A relative reference that does not begin with a slash character is termed a relative-path reference."

b0rk, (edited ) to random
@b0rk@jvns.ca avatar

poll: to switch branches in git, do you use git checkout or git switch?

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@b0rk switch all the way, I find checkout confusing because it does way too many things.

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar
DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

TIL that operations on IORefs (unlike some operations on MVars) are are guaranteed not to be interruptible.

https://hackage.haskell.org/package/base-4.19.1.0/docs/Control-Exception.html#g:13

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

When building Servant applications with persistence, a common (?) pattern is to request a database connection from a pool in the callback we pass to "hoistServer" https://hackage.haskell.org/package/servant-server-0.20/docs/Servant-Server.html#v:hoistServer and then pass the connection down to the handler using ReaderT https://github.com/danidiaz/comments-project/blob/3bb720124b31f0a8e351751bdcc6651ed75d9e27/comments/lib/Comments/Runner.hs#L57
It works, but I'm kinda unhappy about it because it forces you to use ReaderT in those intermediate components that lie between the top-level handler and the repository component which actually uses the connection. 😕

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

You might say "Well, that's not a problem, just make those intermediate components that don't care about the connection polymorphic over MonadUnliftIO! Later, when composing the application, they will be injected a repository that does know about the ReaderT and the connection. Problem solved."

That's true, but what if I wanted those intermediate components to be as dumb as possible? Just plain records of functions in IO, no monad transformers, and no polymorphism over the monad, either?

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

As an alternative to ReaderT and/or polymorphism over the effect monad, I could try to implement some form of "thread-local" storage. 🤔 Some kind of map indexed by ThreadId which would be injected only into those components (like the repository) that require the request-scoped info.

Entries would be allocated / deallocated in the "hoistServer" callback, much like with the ReaderT solution.

Intermediate components could use IO for effects and remain blissfully innocent of the shenanigans.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

The problem of course is that this solution would be less type-safe. If the repository expects an entry for the current ThreadId to exist in the map, and we forgot to set it earlier in the "hoistServer" callback, that would be a runtime error.

It would probably be less efficient as well.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

Eric Torreborre mentions the need for some form of ReaderT at 33:05 in his "Wire all the things" talk:
https://youtu.be/fFCcvsbCrH8?t=1986

DiazCarrete,
@DiazCarrete@hachyderm.io avatar
DiazCarrete, (edited )
@DiazCarrete@hachyderm.io avatar

"I got rid of ReaderT and now my application is hanging by a thread"
https://discourse.haskell.org/t/i-got-rid-of-readert-and-now-my-application-is-hanging-by-a-thread/9330

DiazCarrete, to random
@DiazCarrete@hachyderm.io avatar

In-depth exegesis of the meaning of single letters in my aliases. I'm being so productive you wouldn't believe. Productivity is off the charts right now.

https://github.com/danidiaz/miscellany/blob/4bf8a325165d0e8943fb5a20498c57b0ea8e5a02/linux/.gitconfig#L15

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

Rel8 is a library that teeters between "looking at the instances provides much useful information" and "looking at the instances causes psychic damage".
https://hackage.haskell.org/package/rel8-1.5.0.0/docs/Rel8.html#t:Table

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

Relatedly, it would be a nice feature for Haddock if the instances local to a module could be sorted and grouped for the purposes of documentation and telling a story.

Like "These are the instances for tuples of various sizes" or "this is the base case and these are some instances that recurse".

DiazCarrete,
@DiazCarrete@hachyderm.io avatar
DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar
DiazCarrete,
@DiazCarrete@hachyderm.io avatar

"BLESSED ARE THE POOR IN SPIRIT—Confession of a repentant Effects programmer"

https://abailly.github.io/slides/heureux-les-simples.html

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

I have wondered about this myself:

(24:30) https://youtu.be/fFCcvsbCrH8?t=1468

"registry"-like approaches do seem to make it easier to reuse previously assembled application contexts because the wiring is done through a dictionary-like data structure. You can easily overwrite any key with a different implementation, or with a mock.

Relatedly, they also seem to make it easier to draw diagrams of component dependencies:
https://hackage.haskell.org/package/registry-0.6.1.0/docs/Data-Registry-Dot.html
https://github.com/danidiaz/cauldron/blob/700dafb64ed932eee8b66356e35196c586d7e24c/lib/Cauldron.hs#L123

julesh, to random
@julesh@mathstodon.xyz avatar

I vaguely feel that the AGI singularity cult comes from a mode of thinking that's implicitly aligned with Catholic Neo-Platonism. Like, if everything in the universe is either sentient or it isn't and there's no grey area between then you end up in an absolutist position on abortion. So every AI is either AGI or it isn't, and every AGI is God-like.

It's kind of the exact opposite of your basic starting point of queer theory, that binaries don't exist in nature.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@julesh I think one can be a doomer about AI while having a gradualist view about AI minds.

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar
DiazCarrete,
@DiazCarrete@hachyderm.io avatar
DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

"Nesting APIs and ReaderT environments with Servant"
https://nicolashery.com/nesting-reader-environments-servant/

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

"Spring Boot - The Missing Guide : 6 - How Spring handles Transactions & Security using AOP/Proxies"
https://www.youtube.com/watch?v=jviq49ukATo

The whole playlist: https://www.youtube.com/playlist?list=PLuNxlOYbv61jZL1IiciTgWezZoqEp4WXh

tweet collecting interesting Spring videos: https://twitter.com/jyotirmaya_das/status/1781887932812698058

Demystifying Spring Internals
https://www.youtube.com/watch?v=LeoCh7VK9cg

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@fubaroque Making videos about topics that one feels are underexplained is good.

That said, the reference documentarion for the Spring IOC container is already good https://docs.spring.io/spring-framework/reference/core/beans.html but it's a reference, not focused in the big ideas and motivation behind dependency injection / AOP.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • magazineikmin
  • osvaldo12
  • GTA5RPClips
  • mdbf
  • Youngstown
  • tacticalgear
  • slotface
  • rosin
  • kavyap
  • ethstaker
  • everett
  • khanakhh
  • JUstTest
  • DreamBathrooms
  • InstantRegret
  • cubers
  • normalnudes
  • Leos
  • ngwrru68w68
  • cisconetworking
  • modclub
  • Durango
  • provamag3
  • anitta
  • tester
  • lostlight
  • All magazines