[Haskell-cafe] tail recursion
Daryoush Mehrtash
dmehrtash at gmail.com
Tue Apr 7 03:34:04 EDT 2009
Is the call to "go" in the following code considered as tail recursion?
data DList a = DLNode (DList a) a (DList a)
mkDList :: [a] -> DList a
mkDList [] = error
<http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:error>
"must have at least one element"
mkDList xs = let (first,last
<http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>)
= go last <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>
xs first
in first
where go :: DList a -> [a] -> DList a -> (DList a, DList a)
go prev [] next = (next,prev)
go prev (x:xs) next = let this = DLNode prev x rest
(rest,last
<http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>)
= *go this xs next*
in (this,last
<http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>)
Daryoush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090407/b9236197/attachment-0001.htm
More information about the Haskell-Cafe
mailing list