1

I am new to sml and ml-lex. To convert string to real numbers we use the function real.fromstring. This is my code for conversion where yytext is an array of characters or a string.

getOpt ((Real.fromString(yytext)), 0.0);

I am using the above syntax in ml-lex for tokenising real numbers.

{real} => (REAL(getOpt ((Real.fromString(yytext)), 0.0)));

But i get the error,

math.lex.sml:5.234-5.240 Error: type constructor Assembly.option given 0 arguments, wants 1

Kindly, tell me what is wrong with the fromstring function.

Cherry Cool
  • 69
  • 2
  • 7
  • I don't think the error refers to the code you showed. Search for uses of the parameterised type name `option` in your file, one of it seems to be missing its argument. – Andreas Rossberg Feb 10 '15 at 13:39
  • @AndreasRossberg Actually, there's no other function or parameter of option type. And when I remove the above code from my file, the program works fine. So, it seems to pinpoint to this particular piece. – Cherry Cool Feb 10 '15 at 13:46
  • Then it is perhaps part of the code that's generated by MLlex. Have you looked at that? The error message specifically talks about the (mis)application of a type constructor, and there is none in your snippet. – Andreas Rossberg Feb 10 '15 at 17:23
  • @AndreasRossberg The type constructor that is misapplied is for the `Real`. – ben rudgers Feb 12 '15 at 22:27
  • @benrudgers, I don't know what you mean. `Real` is not a type constructor, nor is it mentioned in the error message. The problem must lie elsewhere in the (generated?) code. – Andreas Rossberg Feb 14 '15 at 08:37

1 Answers1

-1

Caveat: I am unfamiliar with ML-Lex

The syntax for Real.fromString is incorrect. It is a curried function and the call to getOpt should read:

 getOpt(Real.fromString yytext, 0.0)

Example code:

 - getOpt(Real.fromString "1.0", 0.0);
 val it = 1.0 : real
 - getOpt(Real.fromString "a", 0.0);
 val it = 0.0 : real
ben rudgers
  • 3,647
  • 2
  • 20
  • 32
  • This reply doesn't make sense. A function of just one argument cannot be curried. Moreover, `f x` and `f(x)` and `(f(x))` are exactly the same thing, just with redundant parentheses. This definitely cannot have been the problem. – Andreas Rossberg Feb 14 '15 at 08:35