Re: type of dictionary int to int inside other type

"Sébastien Dailly [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
Le 22/04/2015 17:22, Ilia Rassadzin [email protected] [ocaml_beginners] 
a écrit :

> pref is a pythonic dictionary int to int.
>
> how to implement it?

You have to buidl a Map[1] with type key = int, so you first have to 
build your dictionnary like this :

> module Int_Key = struct
>   type t = int
>   let compare = Pervasives.compare
> end
>
> module Dictionary = Map.Make(Int_Key)

Now, the Dictionnary is a module, with type 'a Dictionary.t

If you want a int to int dictionary, this give the following signature : 
int Dictionary.t

This give the following type point :
>
> type point =
>     { id                    : int;
>       x                     : int;
>       y                     : int;
>       z                     : int;
>       pref                  :  int Dictionary.t;
>       mutable obj_id     : int;
>       modulo_squared        : int;
>       cos_phi               : float;
>       cos_theta             : float;
>       mutable cos_circle    : float;
>       mutable eff_modulo    : float;
> };;
>

Take a look at the wiki[2] which explain how the module works.

[1] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Map.Make.html
[2] http://ocaml.org/learn/tutorials/map.html

Regards,

-- 
Sébastien
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.