language design - Why does the power operator in F# only work for floating point numbers? -


I have never seen a language exponent or power operator only for temporary point numbers?

For example:

2 ** 2 throws an error does not support any operator named 'int' type 'Pow' Is

Are there legitimate reasons for this design decision?

(**) and power two There are different things when you see (**) , then you can think of the mathematical formula using logridiments. When you see pown , then this is a series of times multiplied, I think it can be astonishing / confusing for the first time, because in most other languages ​​there is no such difference (mainly because the integer is often floating point Values). Even in mathematics, there is a small difference: see, the first definition only works for positive integers valleys.

Because they are two different (but related) things, they have different signatures here (**) :

  ^ A - & gt; (^ B -> ^ A) When ^ A: (Stable Member Pau: ^ a * ^ b -> ^ a)   

and here pown :

  ^ a -> (Int -> gt; ^ ^): (stable member get_One: -> ^ a) and ^ a: (stable member (*): ^ a * ^ a -> ^ a) and ^ a: (Stable Member (/): ^ a * ^ a -> a)   

If you create your own type, then you only have your a (*) , and (/) to work with pown . The library will loop for you (it has been optimized, it is not naive o (n)).

If you want to use the (**) operator on your type for non-integral values, you have to type the full argument (and this pown is not the same as algorithm.).

I think it was a good design decision to separate the two concepts.

Comments