This is something that has bothered me for a little while. As far as I know, there is no way in Racket to determine the type of some built-in structure in constant time. Traditionally, the solution is to just use predicates, but this is obviously linear in the number of predicates to be tested. It also needs to be extended for every single datatype that gets added to the language (or was simply omitted).
I’d love to be able to have a type-of operator that produces a unique key for each type of data structure Racket has. Why? Well, a little while ago, I tried to implement multimethods in Racket in a safe way[1], and I think my solution was a pretty good one. However, it is currently pretty limited by the fact that it only works with structs, since it uses the structure type as a key for dispatch. It would be really nice to make dispatch O(1) for all conceivable datatypes, including the builtins. This doesn’t really seem all that hard to me, but I could be totally wrong. Things are often a lot harder to do than they initially seem. Is there any reason this isn’t in the language right now? I could imagine an argument that it exposes too much about the implementation, but since the predicates already exist, I’m not sure that’d actually be true. It’d be really helpful for making a useful uniform interface for my multiple-dispatch system. Thanks, Alexis [1]: http://lexi-lambda.github.io/blog/2016/02/18/simple-safe-multimethods-in-racket/ -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/D016C78B-7C44-42C1-90D8-3E8CB8F660EE%40gmail.com. For more options, visit https://groups.google.com/d/optout.
