There is this exercise from purescript book to make a tail recursive function which outputs a fibonacci sequence.
I wrote this as the function currently
--fibTailRec :: forall a. Int a -> Int
fibTailRec n = fib' n 0
where
-- fib' :: Int -> Int ?
fib' n' acc =
if null n'
then acc
else fib' n' (acc - 1) + (acc - 2)
-- fib (n - 1) + fib (n - 2) - for reference only
But it gives me this error
$ spago test
Compiling Test.Main
Warning 1 of 5:
in module Test.Main
at test/Main.purs:7:1 - 7:30 (line 7, column 1 - line 7, column 30)
The import of Data.Maybe is redundant
See https://github.com/purescript/documentation/blob/master/errors/UnusedImport.md for more information,
or to contribute content related to this warning.
Warning 2 of 5:
in module Test.Main
at test/Main.purs:9:1 - 9:24 (line 9, column 1 - line 9, column 24)
The import of Data.Tuple is redundant
See https://github.com/purescript/documentation/blob/master/errors/UnusedImport.md for more information,
or to contribute content related to this warning.
Warning 3 of 5:
in module Test.Main
at test/Main.purs:3:1 - 3:15 (line 3, column 1 - line 3, column 15)
Module Prelude has unspecified imports, consider using the explicit form:
import Prelude (class Eq, class Ord, class Show, Unit, discard, negate, ($), (<$>), (==))
See https://github.com/purescript/documentation/blob/master/errors/ImplicitImport.md for more information,
or to contribute content related to this warning.
Warning 4 of 5:
in module Test.Main
at test/Main.purs:4:1 - 4:21 (line 4, column 1 - line 4, column 21)
Module Test.Examples has unspecified imports, consider using the explicit form:
import Test.Examples (allFiles, allFiles', fact, factTailRec, factors, factorsV2, factorsV3, fib, length, lengthTailRec)
See https://github.com/purescript/documentation/blob/master/errors/ImplicitImport.md for more information,
or to contribute content related to this warning.
Warning 5 of 5:
in module Test.Main
at test/Main.purs:5:1 - 5:24 (line 5, column 1 - line 5, column 24)
Module Test.MySolutions has unspecified imports, consider using the explicit form:
import Test.MySolutions (allTrue, cartesianProduct, countEven, fibTailRec, isEven, isPrime, keepNonNegative, keepNonNegativeRewrite, squared, (<$?>))
See https://github.com/purescript/documentation/blob/master/errors/ImplicitImport.md for more information,
or to contribute content related to this warning.
Error found:
in module Test.Main
at test/Main.purs:126:26 - 126:27 (line 126, column 26 - line 126, column 27)
Could not match type
Int
with type
Array t0
while checking that type Int
is at least as general as type Array t0
while checking that expression 0
has type Array t0
in value declaration main
where t0 is an unknown type
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.
What is actually meant with executing things in the back?