|Newbie questions about Pliant
Dictionary with user-defined type as key
How do you create a Dictionary with a user-defined type as a key?
|Message posted by maybe Todd Fleming on 2001/04/20 00:53:30
|I tried the following:
field Int i
function compare a b -> result
arg DictKey a b
arg Int result
result := compare a:i b:i
gvar (Dictionary DictKey Int) dict
Failed to compile compare (DictKey rw DictKey r)
compile /pliant/language/type/set/dictionary.pli (internals) 146 17
How can I make my compare function known to Dictionary?
|Message posted by maybe Todd Fleming on 2001/04/20 00:55:11
|Sorry about the duplicate message. The forum made it look like the first post failed.
|Message posted by maybe Hubert Tonneau on 2001/04/21 09:11:49
|There is a design problem with the compare function and modules because the
'compare' function (which is not a generic function like others such as 'build'
or 'destroy') is local to your module, and the 'runtime_compile' function
in the dictionaries module does not include it. Patrice is deaply studying the
notion of modules as a compiling environment, so should come with a better
design at some point.
As a dirty ack right now, just add the following line just below your
'compare' function, in order to export it to a module seen by dictionaries
alias compare compare in "/pliant/language/basic/safe.pli"
|Message posted by pom on 2001/04/21 11:07:45
|I propose a simple patch of dictionary.pli that finds the compare function
the same way it gets the hash function.
At a later term, it should be done another way and I will patch the set
constructors as soon as I will have some time to do it :-)
|Message posted by pom on 2001/04/21 11:10:06
|As I am not maintainer of newbie forum, I post the patch in the code forum (which is,
by the way, a good place to put it).
Now you can use Dictionary with your data types without additional aliasing need,
just the way you wrote it at first.