fork download
  1. module type DICTIONARY = sig
  2. type key = string
  3. type 'a t
  4.  
  5. val empty : 'a t
  6. val insert : key -> 'a -> 'a t -> 'a t
  7. val lookup : key -> 'a t -> 'a option
  8. val map : ('a -> 'b) -> 'a t -> 'b t
  9. end
  10.  
  11. module type DICTIONARY_PLUS = sig
  12. include DICTIONARY
  13. val size : 'a t -> int
  14. end
  15.  
  16. module AssocList : DICTIONARY = struct
  17. type key = string
  18. type 'a t = (key * 'a) list
  19.  
  20. let empty = []
  21.  
  22. let insert k v dict =
  23. (k, v) :: dict
  24.  
  25. let rec lookup k dict =
  26. match dict with
  27. | [] -> None
  28. | (k',v)::dict' ->
  29. if k = k' then Some v
  30. else lookup k dict'
  31.  
  32. let rec map fn dict =
  33. List.map (fun (k, v) -> (k, fn v)) dict
  34. end
  35.  
  36. module AssocListPlus : DICTIONARY_PLUS = struct
  37. include AssocList
  38. let size = List.length
  39. end
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
File "prog.ml", line 36, characters 41-96:
Signature mismatch:
Modules do not match:
  sig
    type key = string
    type 'a t = 'a AssocList.t
    val empty : 'a t
    val insert : key -> 'a -> 'a t -> 'a t
    val lookup : key -> 'a t -> 'a option
    val map : ('a -> 'b) -> 'a t -> 'b t
    val size : 'a list -> int
  end
is not included in
  DICTIONARY_PLUS
Values do not match:
  val size : 'a list -> int
is not included in
  val size : 'a t -> int
stdout
Standard output is empty