in the linked playground example, I define a type:
type DoMap map[int]func(Doer) string
Where Doer
in an interface type that I define.
I implement the interface on a concrete type MyDoer
. I'd like to be able to construct a DoMap
where entries into that map contain functions like both of the following:
func(Doer) string // this works
func(*MyDoer) string // this doesn't
func(MyDoer) string // more-or-less the same idea, also doesn't
I can't, and although it's obvious they are different types, I wonder why I can't since function ensures I have to provide a MyDoer
which implements Doer
.
Isn't that enough to ensure I will fulfill my contract with the function?
Is there another way of achieving this?
https://play.golang.org/p/sJ2Rg3neL7
Update
Some comments are of the form "they are different" "that's the spec" but I can pass a MyDoer
to a function that accepts a Doer
- if the interface is implemented: why does putting it into a map change the result?
Update 2
There's a request to explain the "real problem" and a question of why I can't just use a map of types. I'll try best I can:
DoMap
cannot be a map of types. I am writing a library that allows developers to succinctly define state machines, which succeed or fail to transition, based on the output of a developer written function (business logic) that accepts a developer defined type (business message). the library exists to ensure that the series of transitions can be serialized and recorded elsewhere and subsequently verified by third party users of the library. I didn't say all that originally, because it misses the point - there isn't a simple answer.
Now I feel like I am annoying everyone with my impertinent questions, and since I don't exactly have Rob Pike on speed dial, I'll probably delete this, unless some one is willing to trust that I need to do what I need to do, and suggest something.