This is a follow up question to this one. I think I misunderstood a little bit what type is meant to do in Haskell, so here’s, hopefully, a better formulation of the question:
I want to have a function that can be called with exactly two arguments. These arguments must be of different types. For example, one is string, and another is an integer.
Consider this application:
combine "100" 500 -- results in 100500
combine 100 "500" -- results in 100500
combine 100 500 -- raises an exception
combine "100" "500" -- raises an exception
It is not a problem to write a concrete implementation, it is a problem, however, for me, to give this function a proper signature.
I would be also interested to learn whether there is a solution that is more generic (i.e. doesn’t require to specify the concrete types, but only prescribes for the types to be different. So that, for example, you could use this function to “fix” the input to other functions, if it can be fixed by permuting the arguments.
Thank you!
EDIT:
below is an imprecise copy of what I was expecting it to do in Erlang… well, I hope it makes sense, since it should be quite similar…
combine([String], Int)->
io:fwrite("~s~w~n", [[String], Int]);
combine(Int, [String])->
combine([String], Int).
Sjoerd beat me to it, but I prefer my solution so I’ll post it anyway.
Since this doesn’t include a
Combinable a ainstance, trying to use one is a compile-time error rather than a runtime error.