tag:blogger.com,1999:blog-7094652.post6313110452701919984..comments2024-03-23T14:36:09.980+00:00Comments on Neil Mitchell's Blog (Haskell etc): Three Closed GHC Bugs I Wish Were OpenNeil Mitchellhttp://www.blogger.com/profile/13084722756124486154noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-7094652.post-73163966355226599982010-09-21T22:04:26.181+01:002010-09-21T22:04:26.181+01:00saynte: Since you're replacing a crash with de...saynte: Since you're replacing a crash with defined behaviour you can still explain the semaphore the old way, it will just work in more cases. I find it quite natural that semaphores can be negative, since I programmed using as if they were without even thinking they might not be!Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-1273040454870435122010-09-21T21:42:06.354+01:002010-09-21T21:42:06.354+01:00Neil: You make a good point for the obvious extens...Neil: You make a good point for the obvious extension, but not sensibility (likely the harder of the two).<br /><br />For example; it is a general interpretation of semaphores that they restrict usage of a resource up to a maximum: you now allow that maximum to be negative. Under your proposed extension, this fairly common explanation of semaphores is now nonsensical.sayntehttps://www.blogger.com/profile/09919237195037728981noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-21231085404815887512010-09-21T18:23:18.542+01:002010-09-21T18:23:18.542+01:00Duncan: I'm perfectly happy with an enumeratio...Duncan: I'm perfectly happy with an enumeration, whatever people are happy with.<br /><br />saynte: I disagree. The semantics of negative semaphores are obvious - you wait if there are <= 0 resources available, instead of == 0. I think you should have to argue to make a function partially undefined (i.e. crash) instead of just work. There are always alternatives to any concurrency problem - this is more about aiming for total functions over partial ones. In actual fact, I solved my particular problem in an entirely different way, without semaphores, in the end.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-84561224934293127322010-09-20T16:57:50.938+01:002010-09-20T16:57:50.938+01:00I think you really have to make a case why having ...I think you really have to make a case why having a negative quantity is both obvious and sensible, which you haven't done in your bug report. You say it is, but provide no argument for why it is obvious and sensible. I think the reverse argument would be that it's better to have a partial function that behaves as it is supposed to, than a total one that may not meet the general definition of semaphore.<br /><br /><br />In any case, wouldn't QSemN fit your use-case (with positive initial resources)? This was also mentioned in the bug report by igloo.sayntehttps://www.blogger.com/profile/09919237195037728981noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-19549927755569537022010-09-20T16:55:30.544+01:002010-09-20T16:55:30.544+01:00In Cabal we have an enumeration for the OS which i...In Cabal we have an enumeration for the OS which is clearly better than a string. Asking for isWindows is too much though, for purely political reasons, it elevates one over all others (though it is true that it's the most different). But with an enumeration it's still safe and easy to check for windows or other OSs.Duncannoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-91857096724402310692010-09-20T07:01:14.246+01:002010-09-20T07:01:14.246+01:00Sjoerd and sclv: I don't want foldMap or simil...Sjoerd and sclv: I don't want foldMap or similar, I want concatMapM. I want the type to be as restrictive as concatMap (but generalised to monads) and I want the symmetry of having concatMapM. I realise lots of functions generalised it (over monoids, functors etc), but there is an advantage to having the simple one as well (i.e. map and fmap).<br /><br />Josef: I used it in the implementation of a thread pool, to trigger when all the threads had finished - very similarly to thejerfb.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-88542868595182463882010-09-20T00:28:26.964+01:002010-09-20T00:28:26.964+01:00Negative semaphores can be used if your main threa...Negative semaphores can be used if your main thread has, say, dispatched some job out to three other threads and wants to wake up when they are done. Create a semaphore with -2, lock on it (bringing it to -3), and wait for the other three threads to unlock the semaphore, bringing it back up to zero and unlocking the original thread, which now knows the task is done. (Tune numbers as appropriate for the way the library triggers on semaphores.)<br /><br />Whether this is ever the best solution is Haskell specifically I can't attest to, but I've used this trick in non-Haskell situations with an impoverished concurrency story to wring some relatively sophisticated control-inversion behaviors out of environments where people thought this wasn't possible.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-31288067112055981392010-09-19T23:29:07.669+01:002010-09-19T23:29:07.669+01:00foldMap should be a general purpose replacement fo...foldMap should be a general purpose replacement for concatMapM as is, I think?sclvnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-67438711272297631732010-09-19T10:46:50.377+01:002010-09-19T10:46:50.377+01:00I'd be interested to hear about use cases for ...I'd be interested to hear about use cases for semaphores with negative quantities. Do you have any pointers?Josefhttps://www.blogger.com/profile/13272830598221833253noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-58160764071614573782010-09-18T23:28:33.621+01:002010-09-18T23:28:33.621+01:00In the FMList package I've added foldMapA, whi...In the FMList package I've added <a href="http://hackage.haskell.org/packages/archive/fmlist/0.8/doc/html/Data-FMList.html#v:foldMapA" rel="nofollow">foldMapA</a>, which is concatMapM but a bit more general.Sjoerd Visscherhttps://www.blogger.com/profile/10698430967044536619noreply@blogger.com