Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Contrived Haskell example of problem I am trying to solve
- -- Given a function that doubles a number
- double :: Int -> Int
- double x = 2*x
- -- And a function that gives an array of even numbers with a max cutoff
- evens :: Int -> [Int]
- evens max = [double(x) | x <- [1..], double(x) <= max]
- -- How do I keep this from hanging when it gets to max?
- -- Prelude> evens 19
- -- [2,4,6,8,10,12,14,16,18 -- this hangs due to the unbound range
- -- ^CInterrupted.
- -- So how can I get the unbound range to stop?
- -- New to Haskell so I assume there is an easier/better way to do this.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement