Reputation: 140
I have some types :
type client = {nom : nom_client; demande : demande_client}
type itineraire = {num : num_itineraire;
capacite : capacite_itineraire;
liste_clients : client list}
type plan = Vide | Ilist of itineraire list
I can declare clients and itineraires because I simply have to specify the arguments. However I don't know hoe to declare a variable to be of type plan.
type plan only contains a list of itineraire, but doing :
let myPlan = [(an itineraire here)];;
Returns an itineraire list instead of a plan.
So how do I declare a variable of Ilist of itineraire list?
Upvotes: 0
Views: 71
Reputation: 31459
You should use the IList
constructor, that takes an itineraire list
as parameter as indicated in the type declaration, and returns a plan
.
let my_plan = IList [foo; bar; baz]
Note that to get the list corresponding to a plan, you also need to pattern-match on this constructor.
let merge_plans p1 p2 = match p1, p2 with
| p, Vide | Vide, p -> p
| IList l1, IList l2 -> IList (l1 @ l2)
PS: do you really need to have this case distinction? Couldn't you defined plans simply as lists, and use the empty list instead of Vide
?
Upvotes: 2
Reputation: 66818
It seems to me you just left out Ilist
.
let myPlan = Ilist [];
Every value of type plan
has either Vide
or Ilist
as its constructor. That's what the definition means.
Upvotes: 1