How to decode an ADT with circe without disambiguating objects

Enumerating the ADT constructors The most straightforward way to get the representation you want is to use generic derivation for the case classes but explicitly defined instances for the ADT type: import cats.syntax.functor._ import io.circe.{ Decoder, Encoder }, io.circe.generic.auto._ import io.circe.syntax._ sealed trait Event case class Foo(i: Int) extends Event case class Bar(s: String) extends … Read more

Is there a Haskell equivalent of OOP’s abstract classes, using algebraic data types or polymorphism?

Yes, you are correct, you are looking for algebraic data types. There is a great tutorial on them at Learn You a Haskell. For the record, the concept of an abstract class from OOP actually has three different translations into Haskell, and ADTs are just one. Here is a quick overview of the techniques. Algebraic … Read more

What are “sums-and-products” data structures?

What are the traditional sums-and-products data structures he is referring to? In type theory, regular data structures can be described in terms of sums, products and recursive types. This leads to an algebra for describing data structures (and so-called algebraic data types). Such data types are common in statically typed functional languages, such as ML … Read more

Java tagged union / sum types

Make Either an abstract class with no fields and only one constructor (private, no-args, empty) and nest your “data constructors” (left and right static factory methods) inside the class so that they can see the private constructor but nothing else can, effectively sealing the type. Use an abstract method either to simulate exhaustive pattern matching, … Read more

Haskell’s algebraic data types

Haskell’s algebraic data types are named such since they correspond to an initial algebra in category theory, giving us some laws, some operations and some symbols to manipulate. We may even use algebraic notation for describing regular data structures, where: + represents sum types (disjoint unions, e.g. Either). • represents product types (e.g. structs or … Read more