You can define the same interface in F # as follows:
type ISerializer =
abstract ContentType : string
abstract Serialize : obj -> string
abstract Deserialize<'a> : string -> 'a
It is not possible to get the same "internal" polymorphism with a natural functional data type such as a record, so you need to use OO constructs.
If you really wanted to use a record, you can define one wrapper for Deserializeand place it inside the record:
type IDeserializer =
abstract Deserialize<'a> : string -> 'a
type Serializer =
{
ContentType : string
Serialize : obj -> string
Deserializer : IDeserializer
}
but I don’t think it really is worth it.
source
share