lazy-evaluation

Why is the strictness-introducing function called seq?

杀马特。学长 韩版系。学妹 提交于 2021-02-02 00:29:51
问题 I understand the seq function and why it's necessary to introduce strictness for efficiency. What I don't understand is, why is this primitive called seq (and not something to do with strictness)? 回答1: TL;DR: Miranda called it seq , it was introduced when sequence was (probably) already a thing for Monads, and ($!) was known as strict for a short time. Miranda was first It is called seq because it was called seq in Miranda and previous languages, at least according to A History of Haskell:

Why is the strictness-introducing function called seq?

家住魔仙堡 提交于 2021-02-02 00:29:28
问题 I understand the seq function and why it's necessary to introduce strictness for efficiency. What I don't understand is, why is this primitive called seq (and not something to do with strictness)? 回答1: TL;DR: Miranda called it seq , it was introduced when sequence was (probably) already a thing for Monads, and ($!) was known as strict for a short time. Miranda was first It is called seq because it was called seq in Miranda and previous languages, at least according to A History of Haskell:

Why is the strictness-introducing function called seq?

十年热恋 提交于 2021-02-02 00:28:13
问题 I understand the seq function and why it's necessary to introduce strictness for efficiency. What I don't understand is, why is this primitive called seq (and not something to do with strictness)? 回答1: TL;DR: Miranda called it seq , it was introduced when sequence was (probably) already a thing for Monads, and ($!) was known as strict for a short time. Miranda was first It is called seq because it was called seq in Miranda and previous languages, at least according to A History of Haskell:

Rust Inspect Iterator: cannot borrow `*` as immutable because it is also borrowed as mutable

試著忘記壹切 提交于 2021-01-28 18:27:13
问题 Why can't I push to this vector during inspect and do contains on it during skip_while ? I've implemented my own iterator for my own struct Chain like this: struct Chain { n: u32, } impl Chain { fn new(start: u32) -> Chain { Chain { n: start } } } impl Iterator for Chain { type Item = u32; fn next(&mut self) -> Option<u32> { self.n = digit_factorial_sum(self.n); Some(self.n) } } Now what I'd like to do it take while the iterator is producing unique values. So I'm inspect -ing the chain and

Lazy evaluation to annotations expanding function

拥有回忆 提交于 2021-01-27 22:51:05
问题 I wrote a function to expand annotations within groups. function(data, group_col, expand_col){ data %>% dplyr::group_by(!!rlang::ensym(group_col)) %>% dplyr::mutate( !!rlang::ensym(expand_col) = dplyr::case_when( !is.na(!!rlang::ensym(expand_col)) ~ !!rlang::ensym(expand_col) , any( !is.na(!!rlang::ensym(expand_col)) ) & is.na(!!rlang::ensym(expand_col)) ~ paste(unique(unlist(str_split(na.omit(!!rlang::ensym(expand_col)), " ")) ), collapse = " "), TRUE ~ NA_character_ ) ) %>% dplyr::ungroup()

Fail to define an infinite stream

巧了我就是萌 提交于 2021-01-27 12:50:48
问题 I'm working on UPENN Haskell Homework 6 Exercise 5, trying to define a ruler function 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,... where the nth element in the stream (assuming the first element corresponds to n = 1) is the largest power of 2 which evenly divides n . I just came up with an idea to build it without any divisibility testing: data Stream x = Cons x (Stream x) deriving (Eq) streamRepeat x = Cons x (streamRepeat x) interleaveStreams (Cons x xs) (Cons y ys) = Cons x (Cons y

Are promises lazily evaluated?

吃可爱长大的小学妹 提交于 2021-01-27 12:19:43
问题 Is the code below guaranteed to output HERE ? var p = new Promise(() => console.log("HERE")) (That is, does var p = new Promise(fn) always execute fn if p.then(…) is never called to do something with the result?) More specifically, in the context of service workers, if I call Cache.delete() but never call .then() on the return value (or I throw away the return value), is the cache entry guaranteed to be deleted? 回答1: Yes, it is guaranteed. The specification of Promise has this step which will

How lazy evaluation forced Haskell to be pure

你说的曾经没有我的故事 提交于 2020-12-30 05:51:43
问题 I remember seeing a presentation in which SPJ said that lazy evaluation forced them to keep Haskell pure (or something along that line). I often see many Haskellers saying the same. So, I would like to understand how lazy evaluation strategy forced them to keep Haskell pure as opposed to a strict evaluation stragegy ? 回答1: I think the answer by Jubobs already sums it up nicely (with good references). But, in my own words, what I think SPJ and friends are referring to is this: Having to go

implementing a lazy Supplier in java

夙愿已清 提交于 2020-12-29 09:06:20
问题 What is the right paradigm or utility class (can't seem to find a preexisting class) to implement a lazy supplier in Java? I want to have something that handles the compute-once/cache-later behavior and allows me to specify the computation behavior independently. I know this probably has an error but it has the right semantics: abstract public class LazySupplier<T> implements Supplier<T> { private volatile T t; final private Object lock = new Object(); final public T get() { if (t == null) {

implementing a lazy Supplier in java

送分小仙女□ 提交于 2020-12-29 09:04:08
问题 What is the right paradigm or utility class (can't seem to find a preexisting class) to implement a lazy supplier in Java? I want to have something that handles the compute-once/cache-later behavior and allows me to specify the computation behavior independently. I know this probably has an error but it has the right semantics: abstract public class LazySupplier<T> implements Supplier<T> { private volatile T t; final private Object lock = new Object(); final public T get() { if (t == null) {