lazy-evaluation

Disadvantage of unlifted type products?

社会主义新天地 提交于 2019-12-04 16:20:14
问题 In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and (a, (b, c)). If all pattern matches of all products was always irrefutable, then there would be no difference, and (a, b, c) could be syntactic sugar for (a, (b, c)). Why did Haskell choose to lift type products? 回答1: One reason is that implementing seq for an unlifted product requires parallel/interleaved computation, since seq (a, b) True would be supposed to be True if and only if at least one of a

Lazy CSV Filtering / Parsing - Increasing Performance

蹲街弑〆低调 提交于 2019-12-04 15:43:12
Lazy Filtering CSV Files I had the need to filter through millions of log records, stored as numerous CSV files. The size of the records greatly exceeded my available memory so I wanted to go with a lazy approach. Java 8 Streams API With jdk8 we have the Streams API which paired with Apache commons-csv allows us to easily accomplish this. public class LazyFilterer { private static Iterable<CSVRecord> getIterable(String fileName) throws IOException { return CSVFormat .DEFAULT .withFirstRecordAsHeader() .parse(new BufferedReader(new FileReader(fileName))); } public static void main(String[] args

Force lazy entity to load real instance

£可爱£侵袭症+ 提交于 2019-12-04 13:05:03
问题 I have a proxy for a lazy entity which has been created in the session by loading a child entity. A subsequent fetch on the parent entity only returns the NH proxy. I need the actual instance to check the type (the entity has joined subclasses). I must be missing something, but I can't find a way to do this. Session.Refresh(proxy) does not appear to help, nor does any flavour of HQL that I've tried. Can anyone help? 回答1: To force a proxy to be fetched from the database, you can use the

Can the use of C++11's 'auto' deteriorate performance or even break the code?

孤者浪人 提交于 2019-12-04 12:39:08
This question is the opposite of an existing question " Can the use of C++11's 'auto' improve performance? " One of the answers to that question indicated that usage of auto can have not only positive but also negative effects. I believe we need a separate question, with answers focusing on that side of auto . Leon With auto there is no conversion at the variable declaration+initialization line. But if such conversion must happen anyway, it better happen once during initialization than multiple times later. struct X { ... }; struct Y { operator X() const; ... }; Y foo(); // maybe, originally

How do I handle an infinite list of IO objects in Haskell?

拈花ヽ惹草 提交于 2019-12-04 11:18:20
问题 I'm writing a program that reads from a list of files. The each file either contains a link to the next file or marks that it's the end of the chain. Being new to Haskell, it seemed like the idiomatic way to handle this is is a lazy list of possible files to this end, I have getFirstFile :: String -> DataFile getNextFile :: Maybe DataFile -> Maybe DataFile loadFiles :: String -> [Maybe DataFile] loadFiles = iterate getNextFile . Just . getFirstFile getFiles :: String -> [DataFile] getFiles =

If a python iterator returns iterable objects, how can I chain those objects into one big iterator?

ぃ、小莉子 提交于 2019-12-04 11:05:57
I'll give a simplified example here. Suppose I have an iterator in python, and each object that this iterator returns is itself iterable. I want to take all the objects returned by this iterator and chain them together into one long iterator. Is there a standard utility to make this possible? Here is a contrived example. x = iter([ xrange(0,5), xrange(5,10)]) x is an iterator that returns iterators, and I want to chain all the iterators returned by x into one big iterator. The result of such an operation in this example should be equivalent to xrange(0,10), and it should be lazily evaluated.

Is there a Haskell compiler or preprocessor that uses strict evaluation?

不打扰是莪最后的温柔 提交于 2019-12-04 10:22:32
问题 I'm looking for a Haskell compiler that uses strict evaluation by default instead of lazy evaluation. I would just use OCaml, but Haskell's syntax is so much better than OCaml's (and Haskell is pure, and has cool features such as type classes). I'd really rather not constantly put ! s and $! s all over my program. A compiler with a switch or a preprocessor to put in the strictness annotations would be really nice. It would also be helpful if there was a way to use lazy evaluation in certain

Pattern matching and infinite streams

我只是一个虾纸丫 提交于 2019-12-04 10:01:39
问题 So, I'm working to teach myself Scala, and one of the things I've been playing with is the Stream class. I tried to use a naïve translation of the classic Haskell version of Dijkstra's solution to the Hamming number problem: object LazyHammingBad { private def merge(a: Stream[BigInt], b: Stream[BigInt]): Stream[BigInt] = (a, b) match { case (x #:: xs, y #:: ys) => if (x < y) x #:: merge(xs, b) else if (y < x) y #:: merge(a, ys) else x #:: merge(xs, ys) } val numbers: Stream[BigInt] = 1 #::

MATLAB variable passing and lazy assignment

落花浮王杯 提交于 2019-12-04 09:05:52
I know that in Matlab, there is a 'lazy' evaluation when a new variable is assigned to an existing one. Such as: array1 = ones(1,1e8); array2 = array1; The value of array1 won't be copied to array2 unless the element of array2 is modified. From this I supposed that all the variables in Matlab are actually value-type and are all passed by values (although lazy evaluation is used). This also implies that the variables are created on the call stack. Well, I am not judging the way it treats the variables, although I have never seen a second programming language doing this way. I mean, for possibly

Truly declarative language?

余生颓废 提交于 2019-12-04 08:31:44
问题 Does anyone know of a truly declarative language? The behaviour I'm looking for is kind of what Excel does, where I can define variables and formulas, and have the formula's result change when the input changes (without having set the answer again myself) The behaviour I'm looking for is best shown with this pseudo code: X = 10 // define and assign two variables Y = 20; Z = X + Y // declare a formula that uses these two variables X = 50 // change one of the input variables ?Z // asking for Z