Programmation Fonctionnelle, TP3

Version & licenses
Creative Commons License

Programmation Fonctionnelle, TP3 : trie.mli

Guyslain Naves
  1. (** A module for a dictionary of lists of keys *)
  2. module Make : functor (K : Set.OrderedType) ->
  3. sig

  4. type key = K.t

  5. (** ['a t] is the type of dictionaries. A dictionary binds some [key list] to values of type ['a],
  6. they can be understood as partial applications from [key list] to ['a].
  7. *)
  8. type 'a t

  9. (** [empty] is the empty dictionary, no list of keys are bound *)
  10. val empty : 'a t

  11. (** [add list value dict] adds the binding between [list] and [value] to [dict]
  12. if [list] was already bound, the previous binding is simply replaced.
  13. *)
  14. val add : key list -> 'a -> 'a t -> 'a t

  15. (** [mem list dict] checks if [list] is bound to some value in the dictionary [dict] *)
  16. val mem : key list -> 'a t -> bool

  17. (** [find list dict] returns the value to which [list] is bound in [dict],
  18. but raises an error if [list] is not bound
  19. *)
  20. val find : key list -> 'a t -> 'a

  21. (** [longest stream dict] finds the longest prefix of [stream] that is bound in [dict].
  22. If no prefix is bound, it returns [None].
  23. Otherwise, it returns [Some (prefix,remains)] where [prefix] is the list of keys bound in [dict],
  24. and [remains] is the stream of keys following [prefix] in [stream].
  25. *)
  26. val longest : key Stream_lzw.t -> 'a t -> (key list * key Stream_lzw.t) option

  27. (** [fold] is the usual folding function, defined on dictionaries,
  28. it applies its first argument to all the bindings defined in the dictionary in second argument.
  29. *)
  30. val fold : (key list -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b

  31. end