Thanks for all of the responses.
I’m going to mark this thread as resolved. Based on the responses, it seems that it’s not possible to get the name of a type constructor in the general case. Also, it turns out getting the name of the type constructor isn’t actually helpful for solving the use case described in my original post (see below if you want more details about this).
Extra Details
Thinking more about this, Elm’s builtins that generate commands take more than just type constructors. They take functions. For example, NewBook
works as the first parameter of Http.send NewBook bookRequest
not because it’s a type constructor but because it’s a function that matches the expected signature.
So to solve the use case described in my original post, I should be thinking about functions rather than type constructors. This means that my original question about getting the name of a type constructor as a string is not actually helpful in solving my use case.
To solve my use case, I need to share the function between the sending and receiving sides of the port in Elm. I don’t see any nice way of doing this.