Created
February 6, 2014 19:54
-
-
Save josejuan/8851395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lpfib :: Int -> (Int, [Int]) | |
| lpfib 0 = (1, [1]) | |
| lpfib 1 = (1, [1, 1]) | |
| lpfib n = aq `par` bq `pseq` (a + b, as ++ bs ++ [a + b]) | |
| where aq@(a, as) = lpfib (n - 1) | |
| bq@(b, bs) = lpfib (n - 2) | |
| -- por ejemplo | |
| main = getArgs >>= mapM_ print . snd . lpfib . read . head | |
| {- | |
| Al ser lazy, según consume `mapM_` se liberan recursos | |
| (en función del recolector de basuras). | |
| El peor caso es que el primer elemento tarde más que el resto, | |
| en cuyo caso TODO el registro queda en memoria... | |
| -} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment