typeclass Serializable ser (write ser) (read str) typebind Serializable Array ( write = lambda ser ( ...) ) foo = new Array [1,2,3,4] write foo How to work around the impossibility to discriminate based on function return types (like read above).