lazy-evaluation

how to use lazy load or async task in List View

 ̄綄美尐妖づ 提交于 2019-12-24 03:30:28
问题 I am making a list of view in my application that shows all installed applications in the users device. It shows the name and the icon. The list view takes very long to load and the UI is unresponsive while its loading. I have seen the resources that have lazy load and async task tutorials but they all seem to fetch images from the internet. I need to lazy load images that are in the system (which are the application icons). I dont know how to do this with async task either. Can someone

Processing (too) many XML files (with TagSoup)

怎甘沉沦 提交于 2019-12-24 02:16:36
问题 I have a directory with about 4500 XML (HTML5) files, and I want to create a "manifest" of their data (essentially title and base/@href ). To this end, I've been using a function to collect all the relevant file paths, opening them with readFile, sending them into a tagsoup based parser and then outputting/formatting the resultant list. This works for a subset of the files, but eventually runs into a openFile: resource exhausted (Too many open files) error. After doing some reading, this isn

Optimizing lazy collections

核能气质少年 提交于 2019-12-24 01:52:56
问题 This question is about optimizing lazy collections. I will first explain the problem and then give some thoughts for a possible solution. Questions are in bold . Problem Swift expects operations on Collection s to be O(1). Some operations, especially prefix and suffix -like types, deviate and are on the order of O(n) or higher. Lazy collections can't iterate through the base collection during initialization since computation should be deferred for as long as possible until the value is

Optimizing lazy collections

孤街浪徒 提交于 2019-12-24 01:52:50
问题 This question is about optimizing lazy collections. I will first explain the problem and then give some thoughts for a possible solution. Questions are in bold . Problem Swift expects operations on Collection s to be O(1). Some operations, especially prefix and suffix -like types, deviate and are on the order of O(n) or higher. Lazy collections can't iterate through the base collection during initialization since computation should be deferred for as long as possible until the value is

Why is this recursive map function only being applied to the last two elements in the list?

半城伤御伤魂 提交于 2019-12-24 01:18:33
问题 This is the problem given: What are the first 8 elements in the following list? mystery = 0 : 10 : (map(+1)mystery) The answer is [0,10,1,11,2,12,3,13...] But in my opinion the answer should be [0,10,1,11,1,11,2,12] . The following steps show why: 1) We are given ;list [0,10] so after applying the function the first time we have the list [ 0,10,1, 11] 2) Now we have a list [ 0,10,1,11] so after applying the function again the resulting list should be [0,10,1,11,1,11,2,12] Apparently that is

Haskell script running out of space

那年仲夏 提交于 2019-12-24 00:58:50
问题 I'm using project Euler to teach myself Haskell, and I'm having some trouble reasoning about how my code is being executed by haskell. The second problem has me computing the sum of all even Fibonacci numbers up to 4 million. My script looks like this: fibs :: [Integer] fibs = 1 : 2 : [ a+b | (a,b) <- zip fibs (tail fibs)] evens :: Integer -> Integer -> Integer evens x sum | (even x) = x + sum | otherwise = sum main = do print (foldr evens 0 (take 4000000 fibs)) Hugs gives the error "Garbage

Could `if-then-else` (always) be replaced by a function call?

微笑、不失礼 提交于 2019-12-24 00:56:41
问题 This question is out of curiousity about how PLs work, more than anything else. (It actually came to me while looking at SML which differs from Haskell in that the former uses call-by-value - but my question is about Haskell.) Haskell (as I understand) has "call-by-need" semantics. Does this imply that if I define a function as follows: cond True thenExp elseExp = thenExp cond _ thenExp elseExp = elseExp that this will always behave exactly like an if-then-else expression? Or, in another

Delay an evaluation / lazy evaluation in Python

妖精的绣舞 提交于 2019-12-23 23:24:32
问题 I want to delay the evaluation of a call to a member function of an instance of a class until this instance actually exists. Minimum working example: class TestClass: def __init__(self, variable_0): self.__variable_0 = variable_0 def get_variable_0(self): return self.__variable_0 delayed_evaluation_0 = test_class.get_variable_0() # What should I change here to delay the evaluation? test_class = TestClass(3) print(delayed_evaluation_0.__next__) # Here, 'delayed_evaluation_0' should be

Haskell Read Last Line with a Lazy mmap

瘦欲@ 提交于 2019-12-23 23:24:09
问题 I want to read the last line of my file and make sure it has the same number of fields as my first---I don't care about anything in the middle. I'm using mmap because it's fast for random access on large files, but am encountering problems not understanding Haskell or laziness. λ> import qualified Data.ByteString.Lazy.Char8 as LB λ> import System.IO.MMap λ> outh <- mmapFileByteStringLazy fname Nothing λ> LB.length outh 87094896 λ> LB.takeWhile (`notElem` "\n") outh "\"Field1\",\"Field2\",

Applicative parser stuck in infinite loop

拜拜、爱过 提交于 2019-12-23 23:24:05
问题 I'm trying to implement my own Applicative parser, here's the code I use: {-# LANGUAGE ApplicativeDo, LambdaCase #-} module Parser where -- Implementation of an Applicative Parser import Data.Char import Control.Applicative (some, many, empty, (<*>), (<$>), (<|>), Alternative) data Parser a = Parser { runParser :: String -> [(a, String)] } instance Functor Parser where -- fmap :: (a -> b) -> (Parser a -> Parser b) fmap f (Parser p) = Parser (\s -> [(f a, s') | (a,s') <- p s]) instance