This is the function I have now, written in power to two, by changing to
import Math (pow)
[...]
squared :: Array Number -> Array Number
squared arr = (\n -> pow n 2 ) <$> arr
but it gives me a different error output
Error found:
in module Test.MySolutions
at test/MySolutions.purs:42:29 - 42:30 (line 42, column 29 - line 42, column 30)
Could not match type
Int
with type
Number
while checking that type Int
is at least as general as type Number
while checking that expression 2
has type Number
in value declaration squared
See https://github.com/purescript/documentation/blob/master/errors/TypesDoNotUnify.md for more information,
or to contribute content related to this error.
[error] Failed to build.
In PureScript, all number literals that don’t have a decimal point are considered integers. You provide pow, which expects both of its parameters to be Numbers, with an Int (2). So, instead of pow n 2, you should use pow n 2.0.
Personally, I don’t see the need to use pow here and would instead just use n * n. However, pow also works, and you can use that if you prefer.