@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.

chris__martin, to random
@chris__martin@functional.cafe avatar

What if the underlying overhyped and overapplied technology underlying both blockchains and AI, the original solution in search of a problem that gave rise mostly to expensive toys, unreliable devices, and epic startup crashes, was microprocessors

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

Made a video: generating HTML in Haskell using "lucid2"
https://www.youtube.com/watch?v=SQ78GVCzsz0

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

In which I completely mispronounce "lucid", among many other words.

DiazCarrete, to random
@DiazCarrete@hachyderm.io avatar
chris__martin, to random
@chris__martin@functional.cafe avatar

Tuples and curried functions are nice for toys, but they are industrial Haskell's worst enemy. If you're going to be able to jump into a big repo and understand stuff, you need to see record field names.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@chris__martin It's way too easy to fall into the trap of adding yet another positional parameter to a function, rather than taking the effort of refactoring to a record.

A library that has been greatly improved by the use of records is Servant. Trying to define a big REST API without NamedRoutes seems like a chore.

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

lots of info about HKD techniques in this thread

https://discourse.haskell.org/t/hkd-best-or-worst-thing-ever/9450

DiazCarrete, to Java
@DiazCarrete@hachyderm.io avatar

The history of the concept of "bean" in Java frameworks. It has undergone quite a bit of drift!

https://www.youtube.com/watch?v=Z5hxolai4Tk

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

Generating safe links for your REST API with Servant
https://youtu.be/KC64Ymo63hQ?si=I_E17cwA0UBQfmAF

DiazCarrete, to haskell
@DiazCarrete@hachyderm.io avatar

AFAIK, there's not an easy way in Haskell to inspect at the type level what type a field has in a record.

What I mean is that that there doesn't seem to be a type family like

type FieldType :: Type -> Symbol -> Type

that we could invoke in ghci like

:kind! FieldType Person "age"

Why would I want this? For libraries like servant and rel8 that use parameterized records where the types of the fields vary heavily with the type parameter.

I guess I could hack it using generics. 🤔

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@clementd I should try, but HasField uses functional dependencies and I don't know if they're enough to build the FieldType type family on top of them. IIRC, functional dependencies carry less type-level "evidence" than type families, or something like that?

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

@exa The label seems to be working at the term level, doesn't it? I was looking for something at the type level. A type-level "record dot accessor" if you will.

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

"hack it using generics"
^ oh god, my poor memory. I actually did already implement something like this back in the day, using generics.

https://hackage.haskell.org/package/red-black-record-2.1.4.0/docs/Data-RBR.html#t:Value

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

I've published "dani-servant-lucid2" on Hackage. It's a tiny package that provides a HTML content type for Servant, backed by the "lucid2" HTML library.
https://hackage.haskell.org/package/dani-servant-lucid2
https://github.com/danidiaz/dani-servant-lucid2

There was already an integration for an earlier version of lucid https://hackage.haskell.org/package/servant-lucid but not for lucid2. https://github.com/haskell-servant/servant-lucid/issues/26

Also, "dani-servant-lucid2" has a public sublibrary with extra definitions, but it seems as if Hackage doesn't display info for public sublibraries yet.

#Haskell

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

#haskell

image/png

DiazCarrete,
@DiazCarrete@hachyderm.io avatar

btw, why am I throwing a ServerError with HTTP code 200?

I think ServerError is somewhat misnamed: in reality, it can represent any type of response, not only errors.

It's a kind of escape hatch from the typing strictures of Servant: it lets you return any status code and respose body for a request, not just the ones specified in the type-level API.

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

@BoydStephenSmithJr I don't think it's a bad idea!

I believe we can impement in Servant the throwIO behavior I mentioned earlier by catching (some) runtime exceptions in the callback passed to "hoistServer" and re-throwing them in the "proper" way expected by Handler. https://hackage.haskell.org/package/servant-server-0.20/docs/Servant-Server.html#v:hoistServer

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

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, (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 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
  • Leos
  • hgfsjryuu7
  • magazineikmin
  • thenastyranch
  • InstantRegret
  • rosin
  • Youngstown
  • slotface
  • cubers
  • ngwrru68w68
  • mdbf
  • osvaldo12
  • kavyap
  • DreamBathrooms
  • anitta
  • PowerRangers
  • khanakhh
  • everett
  • vwfavf
  • modclub
  • ethstaker
  • tacticalgear
  • GTA5RPClips
  • Durango
  • cisconetworking
  • tester
  • normalnudes
  • provamag3
  • All magazines