[Haskell-cafe] Re: Top Level etc.
k.schupke at imperial.ac.uk
Thu Jan 20 03:50:15 EST 2005
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"
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
the value of '?accum' in the case '' is always zero! How on earth does
the answer five?
More information about the Haskell-Cafe