How to use exponents in PureScript

less than 1 minute read

I’m doing the exercises for PureScript By Example and I needed to raise a number to a power. (exponentiate: to use an exponent). This was not obvious to me. A couple of hints:

  1. Remember that JavaScript uses Math.pow — [^]( is a bitwise XOR operator that has nothing to do with exponentiation.

  2. Use Pursuit to search for Pow. … Wow, that’s a lot of options. It really depends on the type you want to exponentiate. How about a simple Number? It’s actually the fourth one in the list. Math.pow

Here’s how to use it:

import Math (pow)
pow 2.0 4.0
-> 16