Ben Rudiak-Gould wrote:
> len :: [a] -> Int > > len xs = let ?accum = 0 in len' xs > > len' :: forall a. (?accum :: Int) => [a] -> Int > > len' [] = ?accum > len' (x:xs) = let ?accum = ?accum + (1::Int) in len' xs
*Main> :t len' len' :: forall a. (?accum :: Int) => [a] -> Int *Main> len "hello" 5
I don't get this. The second answer (the one quoted above) must be wrong...
len' gets a value only in the empty '[]' case. The recursion is such that the value
of '?accum' is incremented on the return of the recursively called function, therefore
the value of '?accum' in the case '[]' is always zero! How on earth does this get
the answer five?
Keean, _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
