Hi, is the major (or only) application of HKT is to code effect agnostic libraries? I am not able to...
g
Hi, is the major (or only) application of HKT is to code effect agnostic libraries? I am not able to realize any benefit of using them in an application Domain logic, as the implementation of any application is hardly going to change (like from Rx2 to Coroutines or something) and even if I forsee a migration in future (like from blocking to non-blocking)), filling the domain code with HKTs, fx blocks and monad transformers might seem an overkill. Please help me understand if I missing anything. P.S: Also I recently referred to this talk by @raulraja [KotlinConf 2018 - Functional Programming in Kotlin with Λrrow by Raúl Raja Martínez](

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

) and he starts with let’s build a library!
r
Polymorphism has other applications beside changing the effect type. Among others restrict the API a user has access to vs giving the user the full blown API of something like IO. You can argue if this has a lot of application in practice. Additionally polymorphic programs just speak about how something is done with a contract enforced by the type class.
Are there cases where you would ever favor an interface over just a class?. I believe the same reason applies here since polymorphism applies to both subtype polymorphism and also ad-hoc polymorphism with kinds and type classes.
In arrow we recommend whatever suits your use case best as there are good applications for both polymorphic and concrete code. Polymorphic code tends to be always more correct. If something is not working as expected is usually the implementors fault. When you code concrete to IO the laws are more lax because IO implies a lot more than what you are using in your functions in terms of surface api.
g
Thanks @raulraja . Yes correctness is enforced with HKTs. Can you help me with any real world examples where this type of polymorphism is used (may be any Scala examples as well).
r
Most codebases and libraries depending on cats effects are wired like that.
Here is a clear example where polymorphism let's you switch data type, strategy and keep the code concise
g
Thanks @raulraja, I am currently trying to come up with a talk on using HKTs for reusable code on Server side, and researching on isolating areas of code which can be common across heterogeneous services (blocking & non-blocking). Validation is first in my list, Idempotency is another. I am looking to compose some handful of examples to establish a good case for HKTs in prod.