Add support for opaque datatypes

Part of issue #341