In General
You can wrap the recursion within an inner function. For example this function returns a list of descending numbers, starting with the input number x.
binf :: Int -> [Int]
binf x = go x 23
where
go :: Int -> Int -> [Int]
go 0 _ = []
go _ 0 = []
go y rec = [y] ++ (go (y-1) (rec-1))
Here, rec is a recursion counter and the recursion ends when it reaches 0 or when the recursion ended naturally by the input being 0.
If you run binf 50, you will get a result [50, 49, ... , 28], which has a length of 23 - the number specified as initial rec.
In your case
Since your recursion is just appending to a list, and haskell features lazy evaluation, you can solve this differently:
Here however you can use take 23 (binf some_x), since due to Haskell's
laziness, you will then stop calling the binf.
- Willem Van Onsem (comment link)
Double -> [Int]) but can modify the content of it? If yes, you can add an enclosed function that takes the depth as additional parameter and thus hide that away from the callertake 23 (binf some_x), since due to Haskell's laziness, you will then stop calling thebinf.binf x = truncate x : binf (x*2 - fromIntegral (truncate x*2)).