Phantom types without phantom pain

Click for: original source

Phantom types is an interesting feature of the Scala programming language. While extremely useful for library authors, they have a reputation of being too confusing, complex and unnecessary, especially for programmers coming from different backgrounds - weakly typed languages. By Jaroslav Regec.

The idea behind phantom types is quite simple and various use cases turn out to be very powerful. So in the blog post we’ll take a closer look at what phantom types are and how they can be useful even for day to day programming on client projects. Then we’ll deep dive into more advanced use cases that are to be found in ZIO SQL library and at the end we’ll peek into how they power up ZIO’s environment type.

Tha article then mentions:

  • Phantom types 101
  • Phantom types and correct SQL queries
  • Reader monad
  • Environment type R

Phantom type is a type without a value. Its purpose is to bring more type safety to your scala code. Whether it is a library’s DSL or any API at your client project, phantom types can bring a lot of power and correctness to the codebase. Good read!

[Read More]

Tags big-data programming how-to scala java