bonjour j'ai le code suivant :
ma question serais comment je pourais remplacer le where ou le simplifier pour eviter de le repeter aussi souvent merci
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 -- Evaluation des expressions evalExp :: EXP -> MEMORY -> TREE evalExp (CONST x) memory = x evalExp (ID x) memory = getMemory x memory evalExp (ADD x y) memory = if letype(xEval)==(Just IntType) && letype(yEval)==(Just IntType) then TREEVALUE (INT ((getINT xEval) + (getINT yEval))) else TREEVALUE (Error) where xEval = evalExp x memory yEval = evalExp y memory evalExp (SUB x y) memory = if letype(xEval)==(Just IntType) && letype(yEval)==(Just IntType) then TREEVALUE (INT ((getINT xEval) - (getINT yEval))) else TREEVALUE (Error) where xEval = evalExp x memory yEval = evalExp y memory evalExp (MULTI x y) memory = if letype(xEval)==(Just IntType) && letype(yEval)==(Just IntType) then TREEVALUE (INT ((getINT xEval) * (getINT yEval))) else TREEVALUE (Error) where xEval = evalExp x memory yEval = evalExp y memory evalExp (COMP x y) memory = if letype(xEval)==(Just IntType) && letype(yEval)==(Just IntType) then TREEVALUE (BOOL ((getINT xEval) < (getINT yEval))) else TREEVALUE (Error) where xEval = evalExp x memory yEval = evalExp y memory evalExp (NEG x) memory = if letype(xEval)==(Just BoolType) then TREEVALUE (BOOL (not (getBOOL xEval))) else TREEVALUE(Error) where xEval = evalExp x memory evalExp (AND x y) memory = if letype(xEval)==(Just BoolType) && letype(yEval)==(Just BoolType) then TREEVALUE (BOOL ((getBOOL xEval) && (getBOOL yEval))) else TREEVALUE(Error) where xEval = evalExp x memory yEval = evalExp y memory evalExp (OR x y) memory = if letype(xEval)==(Just BoolType) && letype(yEval)==(Just BoolType) then TREEVALUE (BOOL ((getBOOL xEval) || (getBOOL yEval))) else TREEVALUE(Error) where xEval = evalExp x memory yEval = evalExp y memory
Partager