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?


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.

Need Your Help

AS3 FTP Socket fails on 3G network

actionscript-3 sockets air ftp 3g

I have an AS3 Script which connects to an FTP server and retrievs file/folder list.

How to get my tabs centered>

html css tabs center blogger

I have tried making making all the margins 0 auto, I tried changing all the Float: (to center instead of left) this just centered my tabs in the middle of the page going down rather than across. ...