Hi I am trying to implement the function drop in haskell the thing is that I
I have been trying for some time and I came up with this code where I am
trying to do recursion:
drop :: Integer -> [Integer] -> [Integer]
drop 0 (x:xs) = (x:xs)
drop n (x:xs)
|n < lList (x:xs) = dropN (n-1) xs :
|otherwise = []
So I want to understand how would this work and what exacttly should I put
as an answer on line 4 couse that is where I am lost. I know I might got the
base case wrong as well but I don't know what to think for it. I have done
the lList as a function before writing this one. Thanks to those who can
help me understand this. Thanks alot in advance! Have a nice day!
--
View this message in context: http://www.nabble.com/Hi-can-u-explain-me-how-drop-works-in-Haskell-tf32904…
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
In the wikibook article here:
http://en.wikibooks.org/wiki/Haskell/Understanding_monads, which
really does an excellent job explaining things (nuclear waste
woohoo!), I am stuck at the following code snippet:
container >>= fn =
\st -> let (a, st2) = container st
container2 = fn a
in container2 st2
What stumps me is that (>>=) is supposed to return a container, but if
we return (container2 st2) as in the code, then what we're really
returning is the contents of the container! So what would happen if we
do this:
nuclearWasteInContainer >>= processTheWaste >>= thoroughProcessTheWaste
It seems to me that the second (>>=) in the above expression would
have the arguments (nuclearWaste) and (nuclearWasteProcessor), when
what it really expects are (Container nuclearWaste) and
(nuclearWasteProcessor). So isn't something wrong with the definition
of (>>=) above? Or am I missing something?
(I know the article says that the type for their supposed State monad
at that point is not actually correct, and will be clarified further
on, but that seems to be irrelevant to my question.)
TJ the forever noobie.
I've done a quick pass over the 100s of blog articles
written in the last few months about Haskell, collecting and
categorizing the best on Haskell.org:
http://haskell.org/haskellwiki/Blog_articles
Since it would be a real shame to not take advantage of these new
tutorials. That page should serve something like the cookbook page, but
for external contributions.
If you have some older favourites, please add them!
The list might also serve to inspire people to write about areas not yet
well covered... (hint hint: more articles on parallelism, XML, building
servers ... ;)
-- Don