Thanks, that's it. I had just to move the underK call inside the
if:
underK k (x:xs) = if x < k then x : underK k xs
else []
... I'm finding this to be a little too awkward to me!
On 07/09/12 18:18, illusionoflife wrote:
On Monday, July 09, 2012 18:01:49 Carlos J. G. Duarte wrote:
underK k (x:xs) = (if x < k then [x] else []) ++ underK k xs
-- from [2] ... how does this work anyway?
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
Which seems to work ok. How is takeWhile stopping at a given point and my
underK not?
Look. In your implementation `underK' you *always* call itself.
So, actually you implemented filter. takeWhile can be implemented(you can
easily see source
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html.
Take notion that takeWhile do not call itself anymore if predicate is false.
Other question is regarding the "$" and ".". I know the $ has lower priority
and . has more, but is there any more difference that matters, I mean, can
I always use the "$" everywhere. For example, this main also works: main =
putStrLn $ show $ sum $ filter even $ takeWhile (<_M) fibs
Is it doing the same thing?
It only affect amount of parensisis. Point is nice for high-order function
magic.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners