I've got a text file with the following code:
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
evenOdd n = if (mod n 2) == 0 then 1 else 0
sumFib 0 = 0
sumFib 1 = 0
sumFib n = (evenOdd (fib n))*(fib n) + sumFib (n-1)
Basically, I'm trying to define three functions, where the third relies on the first two. However, when I load this in GHCi, while fib works fine, evenOdd gives me the following error:
interactive>:1:1:1 error: Variable not in scope: evenOdd :: Integer -> t
This confuses me, because if I type that exact line of code into *Main>, evenOdd works fine. How can I get this to work?
*Main> evenOdd 202gives1and*Main> fib 21gives17711:edit filename.hsto check if you are actually loading the right file. Maybe you are in the wrong directory / loading up an old version / didn't save properly.evenOdd n = mod n 2, orevenOdd = (`mod` 2)if you're zealous about point-free. Theif/then/elseis unneeded extra work. Of course, the wasted/duplicated work infibandsumFibis going to dwarf that...