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
2 answers

Haskell: if-then-else blocks and data with asymmetrical constructors

I have the following data which can have a Ship or not: data LaserCollisionResult = NoCollision | LaserToLaserCollision Ship | LaserToShipCollision Ship deriving (Eq, Show) then, later on, I am trying to check if a LaserCollisionResult is of type…
2
votes
2 answers

in haskell, how to represent infinite data which is newly defined

I defined a new data type in Haskell in the following way: data Pro = P Int Pro | Idle deriving Show Then I defined a operator which works for this new data type: (>*>) :: Pro -> Pro -> Pro Idle >*> ps = ps P i ps >*> …
Troy Yao
  • 97
  • 7
2
votes
1 answer

Proper use of delayed evaluation in Scala

I am trying to rewrite the following example from the book "Structure and Interpretation of Computer Programs", chapter 3.5.4: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.4 The following are my codes: def addStream(s1 :…
mpchau
  • 21
  • 1
2
votes
2 answers

Is there any safe way to generate a lazy list in IO?

I'd like to have a lazily-generated list of random numbers, and I managed to do it but with unsafeInterleaveIO: rs :: Random a => (a,a) -> IO [a] rs b = do r <- randomRIO b ns <- unsafeInterleaveIO $ rs b return (r:ns) Is there any safe way…
MasterMastic
  • 20,711
  • 12
  • 68
  • 90
2
votes
1 answer

LIMIT optimized queries

Recently I'm getting familiar with Clojure and I am amused with an idea of lazy sequence evaluation which compute values only when it is necessary. I work a lot with PostgreSQL DB and I experienced different performance of queries when LIMIT clause…
2
votes
2 answers

Hidden divs for "lazy javascript" loading? Possible security/other issues?

I'm curious about people's opinion's and thoughts about this situation. The reason I'd like to lazy load javascript is because of performance. Loading javascript at the end of the body reduces the browser blocking and ends up with much faster page…
dlamotte
  • 6,145
  • 4
  • 31
  • 40
2
votes
1 answer

Haskell: Alternative, non-circular definition of Redex?

I got quite confused about what is and is not a redex in Haskell, so I spent some time on it, but I would like feedback whether I got it right. I found this definition of a redex, and it is circular; Etymology : From "reducible expression"…
AnneTheAgile
  • 9,932
  • 6
  • 52
  • 48
2
votes
1 answer

Simple search tree in Haskell: why stack overflow?

I am completely new to Haskell and trying to learn. I decided to write a short (unbalanced) binary search tree code just to get going. It breaks a text into words, adds the words to the binary tree (discarding repetitions), and then traverses the…
Fernando
  • 595
  • 1
  • 3
  • 12
2
votes
1 answer

Ruby Lazy Enumerable flat_map is not very lazy

Edit: Since I wrote the question with a wrong example and didn't describe my issues, I'll do it again! It seems to me that #flat_map, even though part of the Enumerator::Lazy class, is not very enumerable itself. This example correctly…
ChuckE
  • 5,610
  • 4
  • 31
  • 59
2
votes
1 answer

netwire: dealing with laziness(?) in mutually dependent wires

I am trying to make objects bounce off the walls, using mutually dependent velocity and location wires. Simple one-dimentional example looks like this: {-# LANGUAGE Arrows #-} import Prelude hiding ((.), id) import Control.Wire import…
crosser
  • 717
  • 4
  • 17
2
votes
2 answers

Streams (aka "lazy lists") and tail recursion

This question uses the following "lazy list" (aka "stream") type: type 'a lazylist = Cons of 'a * (unit -> 'a lazylist) My question is: how to define a tail-recursive function lcycle that takes a non-empty (and non-lazy) list l as argument, and…
kjo
  • 33,683
  • 52
  • 148
  • 265
2
votes
3 answers

Evaluating dictionary value during json serialization

I'm trying to get a series of serialized dictionaries where only one specific value changes. the ficticious python dict named "obj" _gen = (value for value in range(5,10)) obj = {'mcu': {'led0': {'duty': _gen}}} should "work" like this: >>>…
Daniel F
  • 13,684
  • 11
  • 87
  • 116
2
votes
2 answers

ByteString.Lazy.Char8 (Not enough space)

This code gives : hGetBufSome: resource exhausted (Not enough space) error as soon as it's executed. import qualified Data.ByteString.Lazy.Char8 as B8 main = do (l:_) <- B8.lines `fmap` B8.getContents B8.putStrLn l I'm just trying to…
Dulguun Otgon
  • 1,925
  • 1
  • 19
  • 38
2
votes
2 answers

Efficient Rational Resampling with lazy semantics

To change the sampling rate of a signal, one needs to upsample , filter, then downsample. Doing this naively means inserting zeros into the input signal, correlating with a filter's impulse response, then discarding all but every nth sample of the…
awelkie
  • 2,422
  • 1
  • 22
  • 32
2
votes
0 answers

Lazy load expensive operations using python __get__

I have a huge config file that I need to parse to get different configuration parameters at several classes/modules. I have created a separate module with function to do the parsing and other modules can call this to get the parsed file output. I…
as3rdaccount
  • 3,711
  • 12
  • 42
  • 62