state

Combining multiple states in StateT

左心房为你撑大大i 提交于 2019-11-28 20:37:59
I am writing a program that runs as a daemon. To create the daemon, the user supplies a set of implementations for each of the required classes (one of them is a database) All of these classes have functions have type signatures of the form StateT s IO a , but s is different for each class. Suppose each of the classes follows this pattern: import Control.Monad (liftM) import Control.Monad.State (StateT(..), get) class Hammer h where driveNail :: StateT h IO () data ClawHammer = MkClawHammer Int -- the real implementation is more complex instance Hammer ClawHammer where driveNail = return () --

How to make angular ui-router's parent state always execute controller code when state changes?

夙愿已清 提交于 2019-11-28 20:15:55
Let's say we have a parent-child relationship defined in our $stateProvider as follows: .state('myProfile', { url: "/my/profile", templateUrl: 'my/profile.html', controller: 'MyProfileController' }).state('myProfile.edit', { url: "/edit", templateUrl: 'my/profile.edit.html', controller: 'EditMyProfileController' }); The idea here is that the parent myProfile state is non-editable, but the child myProfile.edit state is the actual form to edit the profile. Let's ignore if this is how a profile page should work - I'm just playing around with things and learning. When a user submits the form, I

pushState: what exactly is the state object for?

一个人想着一个人 提交于 2019-11-28 16:29:50
I've read a dozen of times now that the state object could exists of multiple key|value pairs and that it is associated with the new history entry. But could someone please give me an example of the benefits of the state object? Whats the practical use of it? I can't imagine why not just typing in {} janfoeh Take this small example: run fiddle ( editor view ): You have a page where a user can select a color. Every time they do, we generate a new history entry: function doPushState(color) { var state = {}, title = "Page title", path = "/" + color; history.pushState(state, title, path); }; We

Android save state on orientation change

笑着哭i 提交于 2019-11-28 16:13:56
I've got an Android application which maintains state regarding distance traveled, time elapsed, etc. This state I can conveniently store in an object and store a reference to that object in the Bundle when Android calls onDestroy() when the user changes the screen orientation, then restore the state in onCreate(Bundle savedBundle). However, I also have some state in the Buttons and EditText objects on the screen that I want to persist through screen orientations. For example, in onStart(Bundle savedBundle) I call: _timerButton.setBackgroundColor(Color.GREEN); _pauseButton.setBackgroundColor

ST Monad == code smell?

淺唱寂寞╮ 提交于 2019-11-28 16:11:54
I'm working on implementing the UCT algorithm in Haskell, which requires a fair amount of data juggling. Without getting into too much detail, it's a simulation algorithm where, at each "step," a leaf node in the search tree is selected based on some statistical properties, a new child node is constructed at that leaf, and the stats corresponding to the new leaf and all of its ancestors are updated. Given all that juggling, I'm not really sharp enough to figure out how to make the whole search tree a nice immutable data structure à la Okasaki . Instead, I've been playing around with the ST

STArray documentation for newbies and State/ST related questions

荒凉一梦 提交于 2019-11-28 15:57:56
问题 I have a hard time to understand STArray from the documentation and other howtos/discussion I've found through Google. I've got some more related questions below. According to the documentation, STArray s are Mutable boxed and unboxed arrays in the ST monad. This gave me the impression, that STArray is meant to be used as a state being passed around between functions (imagine you have a vector that has to be updated often). Apparently this is used differently though: ST s (STArray s a e) What

How to preserve iPhone application state before terminating the application?

与世无争的帅哥 提交于 2019-11-28 15:49:47
I have developed an iPhone application with tab bar and navigation controllers. It is working fine for now. Now I want the application to save its state before quitting. Suppose I have 6 tabs and If an incoming call comes , so after relaunching the app I should see the tab selected that was lastly selected . I have seen several questions on this topic but I am more confused after seeing them, can anyone tell me a straight way to do this ? Bryan Henry There is no "one size fits all", exact answer to this question - the implementation of saving application state will depending greatly on the

Where Should Model State Be Stored In Angular.js

﹥>﹥吖頭↗ 提交于 2019-11-28 15:42:06
I'm finding Angular's use of models confusing. Angular seems to take the approach that a model can be anything you like - I.E. Angular does not include an explicit model class and you can use vanilla JavaScript objects as models. In almost every Angular example I've seen, the model is effectively an object, either created by hand, or returned from an API call via a Resource. Because almost every Angular example I've looked at is simple, usually the model data stored on $scope in a controller and any state related to the model, for example selection, is also stored on the $scope in the

React.Component vs React.PureComponent

和自甴很熟 提交于 2019-11-28 15:00:16
The official React docs state that " React.PureComponent 's shouldComponentUpdate() only shallowly compares the objects", and advises against this if state is "deep". Given this, is there any reason why one should prefer React.PureComponent when creating React components? Questions : is there any performance impact in using React.Component that we may consider going for React.PureComponent ? I am guessing shouldComponentUpdate() of PureComponent performs only shallow comparisons. If this is the case, can't said method be used for deeper comparisons? "Furthermore, React.PureComponent 's

Maintaining complex state in Haskell

被刻印的时光 ゝ 提交于 2019-11-28 14:07:37
问题 Suppose you're building a fairly large simulation in Haskell. There are many different types of entities whose attributes update as the simulation progresses. Let's say, for the sake of example, that your entities are called Monkeys, Elephants, Bears, etc.. What is your preferred method for maintaining these entities' states? The first and most obvious approach I thought of was this: mainLoop :: [Monkey] -> [Elephant] -> [Bear] -> String mainLoop monkeys elephants bears = let monkeys' =