[mercury-users] newbie question: instantiating a type (practicing with the tutorial)
Jean-Marc Vanel
jeanmarc.vanel at gmail.com
Thu Sep 23 19:28:38 AEST 2010
Thanks Tomas
It works like this.
This is very useful to use the map library like you showed, but my original
question was related to the example in the (one and only:( ) Mercury
tutorial in paragraph 2. 7 :
http://www.mercury.csse.unimelb.edu.au/information/papers/book.pdf
:- module dictionary.
:- interface.
:- type dictionary(Key, Value).
:- pred search(dictionary(Key, Value)::in, Key::in, Value::out) is semidet.
:- func set(dictionary(Key, Value), Key, Value) = dictionary(Key, Value).
:- implementation.
:- import_module list.
:- type dictionary(Key, Value) == list({Key, Value}).
search([{K, V} | Dict], Key, Value) :-
( if Key = K then Value = V else search(Dict, Key, Value) ).
set(Dict, Key, Value) = [{Key, Value} | Dict].
I tried to make use of this module (admitedly not computationally efficient
but that's not the point).
Can I use this module like is is , or is some init predicate necessary ?
2010/9/23 Tomas By <tomas at basun.net>
> On Thu, September 23, 2010 10:52, Tomas By wrote:
> > | map.insert(Dic0,"jmv","JM Vanel",Dic1),
> > | map.search(Dic1,"jmv",V),
>
> Make that
>
> | map.det_insert(Dic0,"jmv","JM Vanel",Dic1),
> | map.lookup(Dic1,"jmv",V),
>
> /Tomas
>
>
> --------------------------------------------------------------------------
> mercury-users mailing list
> Post messages to: mercury-users at csse.unimelb.edu.au
> Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
> Subscriptions: mercury-users-request at csse.unimelb.edu.au
> --------------------------------------------------------------------------
>
--
Jean-Marc Vanel
Consulting, services, training,
Rule-based programming, Semantic Web
http://jmvanel.free.fr/
EulerGUI, a turntable GUI for Semantic Web + rules, XML, UML, eCore, Java
bytecode
+33 (0)6 89 16 29 52 -- +33 (0)1 39 55 58 16
( we rarely listen to voice messages, please send a mail instead )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20100923/3dc7fed7/attachment.html>
More information about the users
mailing list