Search Results

Search found 9 results on 1 pages for 'strilanc'.

Page 1/1 | 1 

  • Non-trivial functions that operate on any monad

    - by Strilanc
    I'm looking for examples of interesting methods that take an arbitrary monad and do something useful with it. Monads are extremely general, so methods that operate on monads are widely applicable. On the other hand, methods I know of that can apply to any monad tend to be... really, really trivial. Barely worth extracting into a function. Here's a really boring example: joinTwice. It just flattens an m m m t into an m t: join n = n >>= id joinTwice n = (join . join) n main = print (joinTwice [[[1],[2, 3]], [[4]]]) -- prints [1,2,3,4] The only non-trivial method for monads that I know of is bindFold (see my answer below). Are there more?

    Read the article

  • Is it appropriate to try to control the order of finalization?

    - by Strilanc
    I'm writing a class which is roughly analogous to a CancellationToken, except it has a third state for "never going to be cancelled". At the moment I'm trying to decide what to do if the 'source' of the token is garbage collected without ever being set. It seems that, intuitively, the source should transition the associated token to the 'never cancelled' state when it is about to be collected. However, this could trigger callbacks who were only kept alive by their linkage from the token. That means what those callbacks reference might now in the process of finalization. Calling them would be bad. In order to "fix" this, I wrote this class: public sealed class GCRoot { private static readonly GCRoot MainRoot = new GCRoot(); private GCRoot _next; private GCRoot _prev; private object _value; private GCRoot() { this._next = this._prev = this; } private GCRoot(GCRoot prev, object value) { this._value = value; this._prev = prev; this._next = prev._next; _prev._next = this; _next._prev = this; } public static GCRoot Root(object value) { return new GCRoot(MainRoot, value); } public void Unroot() { lock (MainRoot) { _next._prev = _prev; _prev._next = _next; this._next = this._prev = this; } } } intending to use it like this: Source() { ... _root = GCRoot.Root(callbacks); } void TransitionToNeverCancelled() { _root.Unlink(); ... } ~Source() { TransitionToNeverCancelled(); } but now I'm troubled. This seems to open the possibility for memory leaks, without actually fixing all cases of sources in limbo. Like, if a source is closed over in one of its own callbacks, then it is rooted by the callback root and so can never be collected. Presumably I should just let my sources be collected without a peep. Or maybe not? Is it ever appropriate to try to control the order of finalization, or is it a giant warning sign?

    Read the article

  • Why would my wireless cut in and out every minute or so?

    - by Strilanc
    I've been having problems with my wireless. I moved to a new apartment, and the wireless seems incredibly unreliable. Sometimes it will be stable for hours until, all of a sudden, it starts cutting in and out. I'll get 30-90 seconds of normal behavior, then 5-30 seconds of nothing, then repeat. Sometimes the connection will stop working entirely, until I power-cycle the router. It is extremely, extremely annoying. Surfing the web isn't too bad, assuming you can stand the random 5-30 second waits. But some connections are sensitive enough to timeout, and it certainly makes multiplayer games unplayable. Facts: I confirmed the problem using ping google.com -t. I get normal traffic, interspersed with bursts of "Request timed out.". I've never had this problem before with this laptop. I didn't bring my own router or modem to the apartment. I'm using what the old tenant had. Hooking directly to the modem via an ethernet cable results in a stable connection. Temporarily cutting power to the router sometimes fixes the problem. Sometimes it doesn't. I reset the router, but the problem remained. Apparently the previous tenant had issues with the internet, but I don't know what they were specifically. The router is a D-Link DIR-615, and their tech support is useless.

    Read the article

  • Why is my USB-to-VGA'd monitor working, but not showing in Display Settings?

    - by Strilanc
    I have a USB-to-VGA adapter, which I use to connect a second monitor to my laptop (totaling 3 screens). It worked alright with Vista. I upgraded to Windows 7, and now it no longer works properly (I downloaded the latest drivers just to get it to work on 7). The extra monitor is detected and used to extend the desktop (I can move things onto it, etc), but is not shown within the Control Panel. This is annoying because now I can't changes its resolution, set its logical position to match its physical position, etc. Can I do anything, besides waiting for better drivers? I'm mainly concerned with moving its logical position. (I'd also like to understand how Windows can use a monitor it can't detect. Weird.)

    Read the article

  • Is there a term for this concept, and does it exist in a static-typed language?

    - by Strilanc
    Recently I started noticing a repetition in some of my code. Of course, once you notice a repetition, it becomes grating. Which is why I'm asking this question. The idea is this: sometimes you write different versions of the same class: a raw version, a locked version, a read-only facade version, etc. These are common things to do to a class, but the translations are highly mechanical. Surround all the methods with lock acquires/releases, etc. In a dynamic language, you could write a function which did this to an instance of a class (eg. iterate over all the functions, replacing them with a version which acquires/releases a lock.). I think a good term for what I mean is 'reflected class'. You create a transformation which takes a class, and returns a modified-in-a-desired-way class. Synchronization is the easiest case, but there are others: make a class immutable [wrap methods so they clone, mutate the clone, and include it in the result], make a class readonly [assuming you can identify mutating methods], make a class appear to work with type A instead of type B, etc. The important part is that, in theory, these transformations make sense at compile-time. Even though an ActorModel<T> has methods which change depending on T, they depend on T in a specific way knowable at compile-time (ActorModel<T> methods would return a future of the original result type). I'm just wondering if this has been implemented in a language, and what it's called.

    Read the article

  • Is there an open source immutable dictionary for C#, with fast 'With/Without' methods?

    - by Strilanc
    I'm looking for a proper C# immutable dictionary, with fast update methods (that create a partial copy of the dictionary with slight changes). I've implemented one myself, using zippers to update a red-black tree, but it's not particularly fast. By 'immutable dictionary' I don't just mean readonly or const. I want something that has reasonably fast 'With' and 'Without', or equivalent, methods that return a thing with slight modifications without modifying the original. An example from another language is map in Scala

    Read the article

  • Addressing a variable in VB

    - by Jeff
    Why doesn't Visual Basic.NET have the addressof operator like C#? In C#, one can int i = 123; int* addr = &i; But VB has no equivalent counter part. It seems like it should be important. UPDATE Since there's some interest, Im copying my response to Strilanc below. The case I ran into didnt necessitate pointers by any means, but I was trying to trouble shoot a unit test that was failing and there was some confusion over whether or not an object being used at one point in the stack was the same object as an object several methods away.

    Read the article

1