Reputation: 77
In the ensemble.mli file I have
type 'a t;;
val ajouter : 'a -> 'a t -> 'a t
And in the ensemble.ml file:
type 'a t='a list
let rec ajouter =function a -> function
[] ->[a]
|h::t -> if h=a then h::t else h::(ajouter a t)
After compilation:
ocamlc ensemble.mli ensemble.ml
#load "ensemble.cmo"
Ensemble.ajouter 1 [];;
**Error: This expression has type 'a list but an expression
was expected of type int Ensemble.t**
I have to be able to give a detailed explanation about this error but I don't know exactly how to even fix it.So I really need your help.
Upvotes: 1
Views: 45
Reputation: 66823
Your type t
is abstract. So nothing that comes from outside the Ensemble module can have that type. Thus, []
doesn't have the type 'a Ensemble.t
as you would wish.
The usual solution is to export a value named (say) empty
(or vide
) from the module.
Upvotes: 2