I’m working in F# with Akkling so I can use the strongly typed actors on Akka.net but I’ve hit a design limitation within F# and I wondered if there is an elegant way around this.
Take my root message type, I don’t really want to have IActorRef<_> in there because this type will live in a common lib and should not be aware of message system it uses. Also, for easy testing I don’t want to have to create the whole actor system (or test kit).
type MessageType =
| World of WorldMessage
| Location of IActorRef<LocationMessage> * LocationMessage
| Client of IActorRef<LocationMessage> * ClientMessage
A horrible work around is this:
type MessageType<'LocationActor, 'PlayerActor, 'ClientActor> =
| World of WorldMessage<'ClientActor>
| Location of 'LocationActor * LocationMessage<'ClientActor>
| Client of 'ClientActor * ClientMessage<'LocationActor>
Ideally, I would like this but there is a language limitation (Error: Type parameter cannot be used as type constructor):
type MessageType<'a> =
| World of WorldMessage<'a>
| Location of 'a<LocationMessage> * LocationMessage
| Client of 'a<LocationMessage> * ClientMessage