Skip to content

Instantly share code, notes, and snippets.

@tafsiri
Created February 26, 2012 07:28
Show Gist options
  • Save tafsiri/1914723 to your computer and use it in GitHub Desktop.
Save tafsiri/1914723 to your computer and use it in GitHub Desktop.
-- Q4 Write a function that takes an argument x and returns a lazy sequence that has
-- every third number, starting with x. Then write a second function that includes every fifth
-- number beginning with y. Combine these functions through composition to return every eighth
-- number beginning with x + y.
-- sooooo... the first solution to the first two was kind of given in the book (the myrange
-- function) and i don't fully get the third part. From what i understand about function composition
-- the return type of first function must match the argument type of the second function in the chain
-- this makes complete sense; if f . g = \x -> f (g x), the (g x) must result in something f can take
-- in this case both functions takes a number but returns a sequence. This sequence cannot be an
-- input to the second function. I am not sure this question is well formulated.
-- One could use zip to combine the output of these functions (which would produce the result
-- requested), however that is not function composition.
everyN step start = start:(everyN step (start + step))
every3rd = everyN 2
every5th = everyN 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment