J'ai un module Paths pour faire des chemins et des labyrinthes :
Ensuite j'ai un module Rooms pour ajouter des châteaux et des salles :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 module Paths = struct type path = [ | `Exit | `North of path | `South of path | `East of path | `West of path | `Fork of path * path ] let rec eval cont lex = let continue m = if m = `Exit then `Exit else eval cont lex m in function | `Fork(`Fork _,_) -> invalid_arg "Paths.eval" | (`North m | `Fork(`North m,_)) when lex#granted_word("North") -> continue m | (`South m | `Fork(`South m,_)) when lex#granted_word("South") -> continue m | (`East m | `Fork(`East m,_)) when lex#granted_word("East") -> continue m | (`West m | `Fork(`West m,_)) when lex#granted_word("West") -> continue m | `Fork(_,m) -> eval cont lex m | m -> m end
Mon problème:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 module Rooms = struct type room = [ | `Exit | `North of room | `South of room | `East of room | `West of room | `Fork of room * room | `Room of room * room ] let rec eval lex = function | #Paths.path as maze -> Paths.eval eval lex maze | `Room(inside,outside) when lex#granted_word("Enter") -> ignore(eval lex inside); eval lex outside end
Le type qu'évalue Rooms.eval n'est pas égal (est plus restrictif) que mon type Rooms.room.
Partager