Where's the error in this snippet of code?

Ignore the layout I can't find the error, running it gives parse error during compile on pStack, it is not very descriptive and I don't what is wrong. --Stack for the digits for numbers, a modulo b digStack :: Integer->Integer->[Integer] digStack a b | a == 0 = [] | otherwise = (mod a b):(digStack (div a b) b) --Takes a list of remainders and pStack :: [Integer] -> Integer -> [Integer] pStack [] _ = [] pStack (x:xs) a = digStack x a ++ pStack xs I think I will never like Haskell :-)

Alex Gontcharov wrote:
Ignore the layout
pStack needs to be indented to the same level than digStack (or a "where" must be inserted after digStack).
I can't find the error, running it gives parse error during compile on pStack, it is not very descriptive and I don't what is wrong.
after correct indentation, the error message of ghc is quite accurate: Couldn't match `[Integer]' against `Integer -> [Integer]' Expected type: [Integer] Inferred type: Integer -> [Integer] Probable cause: `pStack' is applied to too few arguments in the call (pStack xs) In the second argument of `(++)', namely `pStack xs'
--Stack for the digits for numbers, a modulo b digStack :: Integer->Integer->[Integer] digStack a b | a == 0 = [] | otherwise = (mod a b):(digStack (div a b) b)
--Takes a list of remainders and pStack :: [Integer] -> Integer -> [Integer] pStack [] _ = [] pStack (x:xs) a = digStack x a ++ pStack xs
the last expression should probably be "pStack xs a"
I think I will never like Haskell :-)
Come on, Christian

Alex, AG> Ignore the layout AG> I can't find the error, running it gives parse error during AG> compile on pStack, it is not very descriptive and I don't AG> what is wrong. Well, ignoring the layout is not a good thing here, since that's the one of the causes for your program to not compile. Besides that, the recursive call to pStack needs a second argument.
digStack :: Integer->Integer->[Integer] digStack a b | a == 0 = [] | otherwise = (mod a b):(digStack (div a b) b)
pStack :: [Integer] -> Integer -> [Integer] pStack [] _ = [] pStack (x:xs) a = digStack x a ++ pStack xs {- ADDED: -} a
HTH, Stefan

Stefan Holdermans wrote:
Alex,
AG> Ignore the layout AG> I can't find the error, running it gives parse error during AG> compile on pStack, it is not very descriptive and I don't AG> what is wrong.
Well, ignoring the layout is not a good thing here, since that's the one of the causes for your program to not compile.
Just going off on a short tangent here... Perhaps Alex meant that pStack is local to some other top level declaration (not digStack), but that the rest of that decl was irrelevant and omitted from the question? Regards, Tom
participants (4)
-
Alex Gontcharov
-
Christian Maeder
-
Stefan Holdermans
-
Tom Pledger