Questions tagged [lazy-evaluation]

Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses of its, so that no expression need be evaluated more than once.

Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses thereof, so that no expression need be evaluated more than once.

2555 questions
2
votes
0 answers

Using lazy evaluation to compute a numerical grid

let f m x be a computationally expensive function that takes two arguments and is computed using a numerical algorithm. f is a differentiable function that has the property that the derivate of f m x is equal to f m+1 x. In order to lower the…
felipez
  • 1,212
  • 9
  • 21
2
votes
1 answer

Read a list of integers lazily as a bytestring

I'm trying to find the sum of integers in a file. The code using the normal string is: main = do contents <- getContents L.putStrLn (sumFile contents) where sumFile = sum . map read. words I tried to change it to use the Data.ByteString.Lazy…
Michael Chav
  • 441
  • 5
  • 15
2
votes
1 answer

Forcing eager evaluation of a Haskell list

Going over the "Learn yourself..." book I encountered a BMI calculator app. The app, so far, takes a list of pairs of Double and returns a list of Double: calcBMI :: [(Double, Double)] -> [Dobule] calcBMI xs = [bmi w h | (w, h) <- xs] where bmi…
user2369099
2
votes
1 answer

How does django's pagination work in a django view

So I was reading about pagination, I have done it quite a few times writing this app but I was wondering how does pagination in django work at sql level. from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger def…
Deepankar Bajpeyi
  • 5,661
  • 11
  • 44
  • 64
2
votes
1 answer

What is the exact difference in behavior between `++` and `#:::` when you concatenate two streams?

To be more specific, I had a code similar to the following one (some of you will probably recognize the pattern of the last assignment of the coursera Functional Programming Course), that failed to find the solution with ++ but worked with #::: (the…
Gael
  • 459
  • 3
  • 18
2
votes
1 answer

How to write lazy functions which are chainable, in python?

I want to write functions which are lazy as well as chainable. What would be the best way. I know that one way would be to do yield instead of return. I want these functions to be lazy in the way similar to how sqlalchemy functions are lazy when…
roopesh
  • 1,636
  • 2
  • 13
  • 16
2
votes
2 answers

Define a list of lambdas in Python that is eagerly evaluated

I'd like to programmatically create a list of functions, each of which returns a dictionary with a specific key, and always the same value. That is: l1 = [lambda _: {0: 42}, lambda _: {2: 42}, lambda _: {3: 42}] I'm trying to achieve the same…
Jir
  • 2,985
  • 8
  • 44
  • 66
2
votes
1 answer

Difference between lazy and substitute in R

I'm trying to use the lazyeval package to create non-standard evaluation in R, but was confused about what's the difference between substitute and lazy. df <- data.frame(col1 = runif(10), col2 = runif(10)) > df col1 col2 1 0.54959138…
Jarod Meng
  • 281
  • 1
  • 3
  • 4
2
votes
1 answer

How to stop lazy evaluation slowing down a divide and conquer algorithm

I was using a recursive function in F Sharp to build a particular tree structure, using containers that were evaluated at each stage. I was instructed to use Seq instead because it lazy evaluation should minimize the number of operation. (I…
MatthewJohnHeath
  • 393
  • 2
  • 12
2
votes
2 answers

How do I force a function to be called immediately in Haskell?

This is my code: import Data.Function.Memoize import Debug.Trace foo :: Int -> Int -> Int foo a = memoFix fooMemo where fooMemo f x = a + (trace (show x) cont) where cont = if x == 0 then 0 else x + f (x - 1) main = do print $ foo…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
2
votes
2 answers

Elapsed time in lazy sequence evaluation

Given this code: (reduce my-fun my-lazy-seq) To measure the elapsed time of the entire operation: (time (reduce my-fun my-lazy-seq)) ;;Elapsed time: 1000.1234 msecs How do I measure the elapsed time of this loop at various stages before…
CJLam
  • 801
  • 3
  • 10
  • 15
2
votes
1 answer

Exercise on scala Stream class and theoretical explanation

I am doing an exercise on the scala stream. I had from the book the following code. (I wrote the toList function) trait Stream2[+A] { def uncons: Option[(A, Stream2[A])] def isEmpty: Boolean = uncons.isEmpty def toList: List[A]…
Donbeo
  • 17,067
  • 37
  • 114
  • 188
2
votes
4 answers

Getting every Friday until a certain date, but in a functional style?

For example, I want to get the dates of every Friday from now until 30 days from now. Currently, I can make use of the underscore library and moment.js to do this. But the result is super verbose and annoyingly procedural/imperative. Observe: var…
2
votes
2 answers

MarkLogic, XQuery, pagination, lazy evaluation

MarkLogic documentation describes a fast pagination technique using unfiltered searching somewhat similar to this let $uris := cts:uris((),(), cts:collection-query('fish') ) [1 to 10] for $uri in $uris let $fish := fn:doc($uri) return {…
Andy Key
  • 125
  • 5
2
votes
1 answer

Can Try be lazy or eager in Scala?

AFAIK, Iterator.map is lazy while Vector.map is eager, basically because they are different types of monads. I would like to know if there is any chance of having a EagerTry and LazyTry that behave just like the current Try, but with the latter…
Trylks
  • 1,458
  • 2
  • 18
  • 31