| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| In article <bglt55$2ii$1@wolfberry.srv.cs.cmu.edu>, Martina wrote: > I am working with a program based on SML'97. As I just learned it is > not possible to use "real" to define a datatype, e.g. > datatype <name> = real; What you're trying to do is create a type abbreviation, and SML does that with the `type' keyword: type <name> = real; Unfortunately, SML makes no syntactic distinction between datatype constructors and type/variable names, so entering datatype <name> = real; creates a one-element type named <name> whose only constructor is `real'. > Maybe anyone can explain to me how I can instruct SML'97 to define a > float number. To use reals, you need only enter them as usual: - 5.5; val it = 5.5 : real - 5.5 + 7.7; val it = 13.2 : real One thing to be careful with is the overloaded arithmetical operators -- their resolution is somewhat poorly specified in the Definition, so implementations sometimes differ in their behavior. You may have to add a type constraint in order to force the intended behavior: - fun f x y = (x + y) / y; stdIn:5.6 Error: overloaded variable not defined at type symbol: / type: int uncaught exception Error raised at: ../compiler/TopLevel/interact/evalloop.sml:52.48-52.56 ../compiler/TopLevel/interact/evalloop.sml:35.55 - fun f x y = (x + y) / y : real; val f = fn : real -> real -> real (This is from SML/NJ.) There's no need to define a type abbreviation to use reals. What are you trying to accomplish? William |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.