KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having a problem in fixing a warning that OCaml compiler gives to me. Basically I'm parsing an expression that can be composed by Bool , Int and Float . I have a symbol table that tracks all the symbols declared with their type: type ast_type = Bool | Int | Float and variables = (string, int*ast_type) Hashtbl.t; where int is the index used later in the array of all variables. I have then a concrete type representing the value in a variable: type value = | BOOL of bool | INT of int | FLOAT of float | UNSET and var_values = value array I'm trying to define the behaviour of a variable reference inside a boolean expression so what I do is check that the variable is declared check that the variable has type bool to do this I have this code ( s is the name of the variable): | GVar s -> begin try let (i,t) = Hashtbl.find variables s in if (t != Bool) then raise (SemanticException (BoolExpected,s)) else (fun s -> let BOOL v = Array.get var_values i in v) with Not_found -> raise (SemanticException (VarUndefined,s)) end The problem is that my checks assure that the element taken from var_values will be of type BOOL of bool but of course this constraint isn't seen by the compiler that warns me: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: (FLOAT _ |INT _ |UNSET) How am I supposed to solve this kind of issues? Thanks in advance
Tags (comma-separated)
Save Edits
Cancel