2

My code:

Term :
...
| VAR { try Hashtbl.find var_table $1
         with Not_found ->
      printf "no such variable '%s'\n" $1; 0.0 }    /*(Line:75)*/
...

and when I was run it, under ocamlc -c parser.ml I see:

Error: This expression has type float but an expression was expected of type
         Syntax.term

can everybody help me to prove this problem?? I understand that type of line 75 doesn't match with type Syntax.term that define in Syntax.ml and Syntax.mll, but I want to specify type of 0.0 to Syntax.term to prove it. can I do it??

--------------------EDIT------------------:

term type :

type term =
    TmTrue
  | TmFalse
  | TmIf of term * term * term
  | TmAnd of term * term
  | TmOr of term * term
  | TmXor of term * term
  | TmSum of term * term
  | TmSub of term * term
  | TmMult of term * term
  | TmPow of term * term
  | TmZero
  | TmSucc of term
  | TmPred of term
  | TmIsZero of term
  | TmNot of term

every thing is work correct, where I want to add assignment to my code, I add VAR to Term with above code. I create hashtable and other things for it, but this section make me confuse...

----------------------/EDIT------------------------

tnx ;)

Vandermond
  • 23
  • 4
  • To get a good answer you'll need to show what the type `Syntax.term` looks like. I'd expect there to be a constructor that represents a floating value. You would use this to construct your result. The value `0.0` itself is of type `float`. That's not something you can change. – Jeffrey Scofield Jan 06 '13 at 21:44
  • My term type:type term = TmTrue | TmFalse | TmIf of term * term * term | TmAnd of term * term | TmOr of term * term | TmXor of term * term | TmSum of term * term | TmSub of term * term | TmMult of term * term | TmPow of term * term | TmZero | TmSucc of term | TmPred of term | TmIsZero of term | TmNot of term I want to print "no such variable ..." only and 0.0 is a extra element to my type different with unit... so line 75 may be change if you say.. tnx for your help:) – Vandermond Jan 06 '13 at 22:02
  • Please update your question to include that information. – didierc Jan 06 '13 at 22:11

1 Answers1

3

You don't have a term that can represent the value 0.0. Maybe you should use TmZero?

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • Thank you 'Jeffrey', we test it and this error is solve with your help ;) I think so, but I didn't test this solution My first questioning experience in StackOverFlow is so good;) tnx again... – Vandermond Jan 06 '13 at 22:39