# Scala Isomorphic Types

Reading this blog post from Chuusai, it says:

def size(x : Either[Int, String]) = x match { case Left(i) => i case Right(s) => s.length } size(Left(23)) == 23 // OK size(Right("foo")) == 3 // OK

Either[Int, String] can model the union type Int ∨ String because there is an isomorphism between the two types and their values

What's "there is an isomorphism between the two types and their values" mean?

## Answers

First you have to define the term "values" in the context of Scala. I'm assuming that means canonical expressions with that type, expressions of the form Left(*n*) or Right(*s*) for constant integer *n* or string *s*. Then the isomorphism is a straightforward mapping onto the mathematical type Int ∪ String. But what about, e.g., null, or Right( null )? Do these have images under this mapping? Doesn't seem totally isomorphic to me.