[Haskell-cafe] Re: Top Level etc.
Keean Schupke
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"
> 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,
More information about the Haskell-Cafe
mailing list