#SRTP function using object expression

1 messages · Page 1 of 1 (latest)

warm drift
#

Is there a way to achieve this:

module Pimp =
    let inline operationId (operationData: 'a when 'a: (member OperationId: Guid<OperationId>)) operationId =
        { operationData with OperationId = operationId }

The above code does not compile:
The expression form { expr with ... } may only be used with record types. To build object types use { new Type(...) with ... }

There is no type constraint for ' record'. Can I tell the compiler to treat it as a record otherwise?
Or do I have to use Reflection?

cerulean thistle
#
type Operation<'a> = {
    Id: Guid<OperationId>
    Data: 'a }

module Pimp =
    let inline operationId op id = { op with Id = id }