[Haskell-cafe] Cloud Haskell Appetiser: a taste of distributed programming in Haskell
HTML version: http://www.well-typed.com/blog/68 # Cloud Haskell Appetiser: (part 2 of Parallel Haskell Digest 11) Hello Haskellers! We mentioned in the [last digest][phd-11] that we'd have just a tiny bit more to say about Parallel Haskell. As promised, here is the completed word of month on *actors* and their use in Cloud Haskell. It so happens — what a coincidence! — that Well-Typed's Edsko de Vries has recently published a beta version of the new [distributed-process][dp-announce] implementation on Hackage. We'd love it if you could give it a try let us know any trouble you ran into or ways we could improve things. To help push things along a bit, this word of month will be using the new distributed-process implementation. Also, have you had a chance to fill out the Parallel Haskell Digest Survey? It's collecting data for another couple of weeks. Anything you can tell us in the survey will inform future efforts in building the Haskell community, so if you've got a couple of minutes before Cloud Haskell Time, head over to [Parallel Haskell Digest Survey](http://goo.gl/bP2fn) Many thanks! ## Word of the month The word of the month series has given us a chance to survey the arsenal of Haskell parallelism and concurrency constructs: *some low level foundations (sparks and threads), *three ways to do parallelism (parallel arrays, strategies, dataflow), *and some concurrency abstractions (locks, transactions, channels) The Haskell approach has been to explicitly recognise the vastness of the parallelism/concurrency space, in other words, to provide a multitude of right tools for a multitude of right jobs. Better still, the tools we have are largely interoperable, should we find ourselves with jobs that don't neatly fit into a single category. The Haskell of 2012 may be in a great place for parallelism and concurrency, but don't think this is the end of the story! What we've seen so far is only a snapshot of the technology as it hurtles through the twenty-tens (How quaint are we, Future Haskeller?). While we can't say what exactly the future will bring, we can look at one of the directions that Haskell might branch into in the coming decade. The series so far has focused on things you might do with a single computer, using parallelism to speed up your software, or using concurrency abstractions to preserve your sanity in the face of non-determinism. But now what if you have more than one computer? ### Actors Our final word of the month is *actor*. Actors are not specific to distributed programming; they are really more of a low level concurrency abstraction on a par with threads. And they certainly aren't new either. The actor model has been around since the 70s at least, and has been seriously used for distributed programming since the late 80s with Erlang. So what makes an actor an actor? Let's compare with threads +--+-+ | **Actor**| **Thread** | +==+=+ | can create more actors | can create more threads | +--+-+ | can have private local state | can have private local state| +--+-+ | has NO shared state | has limited shared state| | (isolated from other actors!)| | +--+-+ | communicates with other actors | communicates with other | | via asynchronous message passing | threads via shared variables| +--+-+ The essential difference between actors and threads is the isolation and message passing. There aren't any holes punched into lids here, but you can always shine a message from one jam jar to another, perhaps hoping they send you one of their own. The appeal of actors is thus a kind of simplicity, where avoiding shared state eliminates a class of concurrency bugs by definition, and where each actor can be reasoned about in isolation of its brethren. This sort of thing may perhaps strike a chord with us functional programmers, and actually, there is quite a bit of actor-related work in Haskell: a handful of packages offering the actor as concurrency primitive, Martin Sulzmann's [multi-headed twist][mh-actors] on the model; [Communicating Haskell Processes][chp] exploring an actor-ish cousin known as CSP. Finally, there's [Cloud Haskell][ch-pdf], which in explicit homage to Erlang, applies the actor model to distributed programming. ### Glimpse of Cloud Haskell We'll be taking a quick look at Cloud Haskell in this word of the month, unfortunately with only the most fleeting of glimpses. If squirting money between bank accounts is the transactional hello
Re: [Haskell-cafe] Haskell's type inference considered harmful
However, if your are using ExtendedDefaultRules then you are likely to know you are leaving the clean sound world of type inference. First of all, ExtendedDefaultRules is enabled by default in GHCi. Second, my example will work without ExtendedDefaultRules, in pure Haskell98. It is even shorter: instance Num Char main = do x - return [] let y = x print . fst $ (x, abs $ head x) -- let dead = if False then y == else True return () The printed result is either [] or . Mainly, if the point is to demonstrate the non-compositionality of type inference and the effect of the dead code, one can give many many examples, in Haskell98 or even in SML. Here is a short one (which does not relies on defaulting. It uses ExistentialQuantification, which I think is in the new standard or is about to be.). {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Show a = Foo [a] main = do x - return [] let z = Foo x let dead = if False then x == else True return () The code type checks. If you _remove_ the dead code, it won't. As you can see, the dead can have profound, and beneficial influence on alive, constraining them. (I guess this example is well-timed for Obon). For another example, take type classes. Haskell98 prohibits overlapping of instances. Checking for overlapping requires the global analysis of the whole program and is clearly non-compositional. Whether you may define instance Num (Int,Int) depends on whether somebody else, in a library you use indirectly, has already introduced that instance. Perhaps that library is imported for a function that has nothing to do with treating a pair of Ints as a Num -- that is, the instance is a dead code for your program. Nevertheless, instances are always imported, implicitly. The non-compositionality of type inference occurs even in SML (or other language with value restriction). For example, let x = ref [];; (* let z = if false then x := [1] else ();; *) x := [true];; This code type checks. If we uncomment the dead definition, it won't. So, the type of x cannot be fully determined from its definition; we need to know the context of its use -- which is precisely what seems to upset you about Haskell. To stirr action, mails on haskell-cafe seem useless. What made you think that? Your questions weren't well answered? What other venue would you propose? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Relational Algebra library: first version on GitHub
Hello, A couple of weeks ago I asked if there was interest in a library that implements a type-safe relational algebra. The response was positive, so I have spruced up the code I had a bit and created a repository on GitHub at: https://github.com/PaulVisschers/relational-algebra It is a very rudimentary version. The code is not documented and there is only a very basic example database in Test.hs. It might be helpful to look at HaskellDB's PrimQuery and PrimExpr, as this library is mostly a direct copy from that (but typed). I will add some decent examples of expressions and queries shortly. If you check it out, please comment on it and let me know if you want to contribute. Since this is going to be my first release, any feedback is welcome. Paul Visschers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] TLS 0.9.6, question about session resumption.
Hi Cafe, I am trying to use the TLS package from hackage, and it works fine so far -- except when a client wants to do session resumption (note I am not an expert in TLS, so it might be something quite simple). In that case, I get an alert, unexpected message, during handshake. The handshake goes like this: ClientHello (with a SessionID) ServerHello (with the same SessionID) ServerHelloDone and then the server says (AlertLevel_Fatal,UnexpectedMessage) I'm not sure whether the ServerHelloDone should happen when resuming. Does anyone have a hint what may be going wrong? I am using TLS10 and the tls package with version 0.9.6. Thanks, Christian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monads with The contexts?
Dear Oleg, You're right. The points boil down to That assumption (that the deviations are small) is not stated in types and it is hard to see how can we enforce it. and even if it's small, there's corner cases at df/dx = 0 or df/dx = infinity (as you have mentioned.) Thanks to your advices, I'll look for other ways to set up probabilistic computations. 2012/7/19 o...@okmij.org: http://en.pk.paraiso-lang.org/Haskell/Monad-Gaussian What do you think? Will this be a good approach or bad? I don't think it is a Monad (or even restricted monad, see below). Suppose G a is a `Gaussian' monad and n :: G Double is a random number with the Gaussian (Normal distribution). Then (\x - x * x) `fmap` n is a random number with the chi-square distribution (of the degree of freedom 1). Chi-square is _not_ a normal distribution. Perhaps a different example is clearer: (\x - if x 0 then 1.0 else 0.0) `fmap` n has also the type G Double but obviously does not have the normal distribution (since that random variable is discrete). There are other problems Let's start with some limitation; we restrict ourselves to Gaussian distributions and assume that the standard deviations are small compared to the scales we deal with. That assumption is not stated in types and it is hard to see how can we enforce it. Nothing prevents us from writing liftM2 n n in which case the variance will no longer be small compared with the mean. Just a technical remark: The way G a is written, it is a so-called restricted monad, which is not a monad (the adjective `restricted' is restrictive here). http://okmij.org/ftp/Haskell/types.html#restricted-datatypes -- Takayuki MURANUSHI The Hakubi Center for Advanced Research, Kyoto University http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] TLS 0.9.6, question about session resumption.
Hi, 2012/7/21 C Gosch ch.go...@googlemail.com: I am trying to use the TLS package from hackage, and it works fine so far -- except when a client wants to do session resumption (note I am not an expert in TLS, so it might be something quite simple). In that case, I get an alert, unexpected message, during handshake. The handshake goes like this: ClientHello (with a SessionID) ServerHello (with the same SessionID) ServerHelloDone Not an expert either, but section 7.4 of the TLS 1.2 spec (rfc 5246) does seem to say that this ServerHelloDone should be a Finished message instead. and then the server says (AlertLevel_Fatal,UnexpectedMessage) Do you mean that the client says this? If so, this may obviously be correct if the server sends the wrong message. Pehaps you can test with a different server implementation? I'm not sure whether the ServerHelloDone should happen when resuming. Does anyone have a hint what may be going wrong? I am using TLS10 and the tls package with version 0.9.6. Bye Dominique ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relational Algebra library: first version on GitHub
Hello there Paul, Paul Visschers m...@paulvisschers.net wrote: A couple of weeks ago I asked if there was interest in a library that implements a type-safe relational algebra. The response was positive, so I have spruced up the code I had a bit and created a repository on GitHub at: https://github.com/PaulVisschers/relational-algebra It is a very rudimentary version. The code is not documented and there is only a very basic example database in Test.hs. It might be helpful to look at HaskellDB's PrimQuery and PrimExpr, as this library is mostly a direct copy from that (but typed). I will add some decent examples of expressions and queries shortly. If you check it out, please comment on it and let me know if you want to contribute. Since this is going to be my first release, any feedback is welcome. Well, the demonstration could be a bit more comprehensive. I would be very interested in seeing queries, especially nontrivial ones with joins and such. Would you mind writing a more comprehensive demonstration? Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relational Algebra library: first version on GitHub
Great / thanks!!! This will be incredibly helpful for some of my present work. :-) On Saturday, July 21, 2012, Paul Visschers wrote: Hello, A couple of weeks ago I asked if there was interest in a library that implements a type-safe relational algebra. The response was positive, so I have spruced up the code I had a bit and created a repository on GitHub at: https://github.com/PaulVisschers/relational-algebra It is a very rudimentary version. The code is not documented and there is only a very basic example database in Test.hs. It might be helpful to look at HaskellDB's PrimQuery and PrimExpr, as this library is mostly a direct copy from that (but typed). I will add some decent examples of expressions and queries shortly. If you check it out, please comment on it and let me know if you want to contribute. Since this is going to be my first release, any feedback is welcome. Paul Visschers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Darcs / ByteString optimisation
Hi, I'm currently investigating darcs' performance issues. The first thing I looked at was ByteString.concat, which seems to allocate a lot of extra objects. Here is the standard definition: concat :: [ByteString] - ByteString concat [] = empty concat [ps] = ps concat xs = unsafeCreate len $ \ptr - go xs ptr where len = P.sum . P.map length $ xs go a b | a `seq` b `seq` False = undefined go []_ = return () go (PS p s l:ps) ptr = do withForeignPtr p $ \fp - memcpy ptr (fp `plusPtr` s) (fromIntegral l) go ps (ptr `plusPtr` l) I had a bad feeling about (sum . map) inside len, so I replaced it (inside darcs) with a stricter-looking one: myconcat :: [B.ByteString] - B.ByteString myconcat [] = B.empty myconcat [ps] = ps myconcat xs = BI.unsafeCreate len $ \ptr - go xs ptr where len = foldl' (\a b - a + B.length b) 0 xs go a b | a `seq` b `seq` False = undefined go []_ = return () go (BI.PS p s l:ps) ptr = do withForeignPtr p $ \fp - BI.memcpy ptr (fp `plusPtr` s) (fromIntegral l) go ps (ptr `plusPtr` l) Profiling the original one gives me 2,042,215,624 bytes allocated in the heap 3,131,672,496 bytes copied during GC 363,380,328 bytes maximum residency (43 sample(s)) 2,517,336 bytes maximum slop 643 MB total memory in use (50 MB lost due to fragmentation) while the second, with no other changes, gives 1,774,403,640 bytes allocated in the heap 2,656,774,296 bytes copied during GC 358,131,264 bytes maximum residency (42 sample(s)) 1,577,080 bytes maximum slop 614 MB total memory in use (50 MB lost due to fragmentation) Is it possible that the code using ByteString.concat is preventing the compiler from doing this optimisation? Thankyou, Luke Worth___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] System.Win32.Registry... Help?
Hi, I'm working on a project that will require me to create and possibly set registry keys. I don't have much experience with programming on Windows either, but I'm having to learn as you don't get many *nix PCs at a computer repair shop, lol. I found a mailing list post showing how to read registry keys and was able to make a function based off of it, but I have no idea what to put into some of the arguments for regSetValueEx or regCreateKeyEx, so I'm stuck. Also, what's the best way to recursively traverse trees in the registry, are there any functions for it? Can someone please help me out with this? Thank you. {-# LANGUAGE ForeignFunctionInterface #-} import System.Win32.Types import System.Win32.Registry import Foreign.Ptr (castPtr) import Foreign.Marshal.Alloc (allocaBytes) import Foreign.C.String (peekCWString, withCWString) import Control.Exception (bracket, throwIO) -- // parse a string from a registry value of certain type parseRegString :: RegValueType - LPBYTE - IO String parseRegString ty mem | ty == rEG_SZ= peekCWString (castPtr mem) | ty == rEG_EXPAND_SZ = peekCWString (castPtr mem) = expandEnvironmentStrings | otherwise = ioError (userError Invalid registry value type) -- // FFI import of the ExpandEnvironmentStrings function needed -- // to make use of the registry values expandEnvironmentStrings :: String - IO String expandEnvironmentStrings toexpand = withCWString toexpand $ \input - allocaBytes 512 $ \output - do c_ExpandEnvironmentStrings input output 256 peekCWString output foreign import stdcall unsafe windows.h ExpandEnvironmentStringsW c_ExpandEnvironmentStrings :: LPCTSTR - LPTSTR - DWORD - IO DWORD get_key :: HKEY - String - String - IO String get_key cat loc key = bracket op regCloseKey $ \x - allocaBytes 512 $ \mem - do ty - regQueryValueEx x key mem 512 parseRegString ty mem where op = regOpenKeyEx cat loc kEY_QUERY_VALUE set_key :: HKEY - String - String - IO () set_key cat loc key = regSetValueEx cat loc rEG_SZ??? LPTSTR? What do I put here? magic_win32_number_here? where op = regOpenKeyEx cat loc kEY_SET_VALUE main = get_key hKEY_CURRENT_USER loc key = print where loc = Software\\7-Zip key = Test ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] System.Win32.Registry... Help?
On Sun, Jul 22, 2012 at 5:43 PM, Tim Matthews tim.matthe...@gmail.comwrote: On Sun, Jul 22, 2012 at 5:11 PM, Anonymous Void bitsofch...@gmail.comwrote: but I have no idea what to put into some of the arguments for regSetValueEx or regCreateKeyEx, Those are just plain bindings to windows function so refer to msdn http://msdn.microsoft.com/en-us/library/windows/desktop/ms724923%28v=vs.85%29.aspx ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe