Reputation: 9370
Hello can someone explain to me why this custom implementaiton of foldl is not in scope?
afold::(a->b->a)->a->[b]->a
afold tsf accu (x:xs)=afold tsf (tsf accu x) xs
afold _ accu []=accu
I've tried running it like this :
afold (\x y-> show y:x) [] [1,2,3,4]
and i get the error:
Variable not in scope:
afold :: ([String] -> () -> [String]) -> [a0] -> [Integer] -> t
When i try to use it even simpler like this :
afold (\x y-> x+y) 0 [1,2,3,4]
i get the error:
:: (Integer -> Integer -> Integer) -> Integer -> [Integer] -> t
Why isn't the output inferred?Why is it still t
in the second example?
Upvotes: 1
Views: 444
Reputation: 9370
The problem was that i didn't place the method inside a module
,and load it.Once i enclosed the method in a module and loaded it in ghci it worked.
module Test where
afold::(a->b->a)->a->[b]->a
afold tsf accu (x:xs)=afold tsf (tsf accu x) xs
afold _ accu []=accu
In GHCI:
:load Test
Upvotes: 3