![]() |
![]() |
| Benefits of OCaml |
Benefits of OCamlArithmeticIn order to type check arithmetic over different types of number, OCaml uses slightly different operator names for different numeric types. Most notably, integer arithmetic uses # 1 + 2 * 3;; - : int = 7 # 1. +. 2. *. 3.;; - : float = 7. Attempting to use an operator of one type on a value of another type results in a type error: # 1. +. 2 *. 3.;; This expression has type int but is here used with type float Operators can be used in prefix notation by bracketing them: # ( + ) 1 2;; - : int = 3 This can be useful in conjuction with currying. Although the use of separate sets of operators for different types of number differs from conventional mathematics and requires extra care, it improves upon the reliability of languages with implicit casting (e.g. what is the value of 3.0-1/5 in C) and languages with ad-hoc polymorphic numbers (like SML).
|
| © Flying Frog Consultancy Ltd., 2007 | Contact the webmaster |