immutability

Does “<-” mean assigning a variable in Haskell?

白昼怎懂夜的黑 提交于 2019-12-07 15:36:18
问题 Just started Haskell, it's said that everything in Haskell is "immutable" except IO package. So when I bind a name to something, it's always something immutable? Question, like below: Prelude> let removeLower x=[c|c<-x, c `elem` ['A'..'Z']] Prelude> removeLower "aseruiiUIUIdkf" "UIUI" So here: 1. “removeLower" is an immutable? Even it's a function object? But I can still use "let" to assign something else to this name. 2. inside the function "c<-x" seems that "c" is a variable. It is assigned

Akka and its Error Kernel

混江龙づ霸主 提交于 2019-12-07 11:40:33
问题 I am reading the Akka ( Java lib ) docs and need clarification on some of their own proclaimed Akka/Actor Best Practices. Actors should not block (i.e. passively wait while occupying a Thread) on some external entity...The blocking operations should be done in some special-cased thread which sends messages to the actors which shall act on them. So what does a code example of this look like in Akka/Java? If an Actor isn't an appriote place to put code that has to block, then what does satisfy

Immutability and thread-safety in Scala

一曲冷凌霜 提交于 2019-12-07 11:30:21
问题 I'm reading the book Java concurrency in practice and when I read about the relation between immutability and thread-safety I tried to get deeper. So, I discovered that there is at least a use case in which the construction of an immutable class in Java can lead to the publishing of a non properly constructed object. According to this link, if the fields of the class are not declated final , the compiler could reorder the statements that needs to be done in order to construct the object. In

Why don't the wrapper classes for Primitives have a setter?

痞子三分冷 提交于 2019-12-07 10:54:30
问题 What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Integer x = new Integer(5); x++; The previous code behind the scenes is performing autoboxing . Something like: int x_tmp = x.intValue(); x_tmp++; x = new Integer(x

Lazily grouping a flat sequence in F#

拥有回忆 提交于 2019-12-07 08:12:55
问题 Given a sequence of items as follows: [ ("a", 1); ("a", 2); ("a", 3); ("b", 1); ("c", 2); ("c", 3) ] How can I convert this lazily into: { ("a", { 1; 2; 3}); ("b", { 1 }); ("c", { 2; 3}) } You can assume that the input data source is already sorted on the grouping key element e.g. "a" "b" and "c". I'm using the { } there to indicate that it's a lazily-evaluated sequence of items. I've gotten it working imperatively with two while loops operating over the IEnumerator of the source sequence,

immutability of a class when an instance variable present as arraylist

老子叫甜甜 提交于 2019-12-07 06:49:30
问题 I have a class which is immutable Suppose I have a getter method for a member variable of type ArrayList. In that case when I get a reference to that variable, I can add or remove an element from it. In that case immutability seems to get violated. Can anyone explain this concept in details? 回答1: You are indeed right. Immutability is violated. To make a class immutable, you need to make sure that all of its getters return safe copies of any class whose state could otherwise change. 回答2: You

Changes to object made with Object.assign mutates source object

丶灬走出姿态 提交于 2019-12-07 05:36:07
问题 I have following reducer code in my react-redux app: case 'TOGGLE_CLIENT_SELECTION': const id = action.payload.id; let newState = Object.assign({}, state); newState.list.forEach((client) => { if (client.id == id) client.selected = !client.selected; }); console.log(state.list[0].selected + ' - ' + newState.list[0].selected) return newState; If I got it right - Object.assign creates brand new object, but console.log displays "true - true" of "false - false". Any thoughts why it behaves like

ImmutableArray<> behaves differently than Array<> for nested Select with index

对着背影说爱祢 提交于 2019-12-07 04:45:16
问题 I am encountering what seems to be a very weird bug in ImmutableArray<> (with BCL Immutable collections v1.0.12.0, runtime .NET 4.5): I have the following two identical structs exactly in the same source file under the same namespace: public struct WeightedComponent { public readonly IComponent Component; public readonly decimal Weight; public WeightedComponent(IComponent component, decimal weight) { this.Component = component; this.Weight = weight; } } public struct WeightedComponent2 {

Why does F# Interactive behave differently than compiler with regards to immutable value definition?

こ雲淡風輕ζ 提交于 2019-12-07 04:22:58
问题 In reading John Palmer's answer to What is the difference between mutable values and immutable value redefinition?, John notes that This sort of redefinition will only work in fsi. In working with F# Interactive (fsi) I guess I subconsciously knew it, but never paid attention to it. Now that it is apparent, why the difference? More specifically please explain how the internals are different between fsi and the compiler such that this occurs by design or result of differences? If the answer

Aren't String objects in Java immutable? [duplicate]

点点圈 提交于 2019-12-07 04:11:24
问题 This question already has answers here : Immutability of Strings in Java (26 answers) Closed 4 years ago . String s = ...; s = s.substring(1); Is this possible? I thought you can't change a String object in Java. 回答1: String objects are immutable. String references , however, are mutable. Above, s is a reference. 回答2: String objects are immutable, meaning that the value of the instance referred to by s cannot change. Your code does not mutate the instance. Rather, it changes the s reference