Re: [Haskell-cafe] Automated tests with cabal
On 10 March 2011 08:12, Hauschild, Klaus (EXT) klaus.hauschild@siemens.com wrote: Hi Haskellers, I read about the cabal features for running test code from Setup.hs with defaultMainWithHooks. I'm looking for more generic code that allows me to place any haskell in a subdirectory test or so and cabal test will run this test without any modification of my Setup.hs. Is there a possibility? There is. The just released Cabal- 1.10.1.0 and cabal-install-0.10.2 have support for test-suites. The documentation is not online yet so here's an example from my threads package: http://code.haskell.org/~basvandijk/code/threads/threads.cabal Make sure you specify: cabal-version: = 1.9.2 A test-suite looks a lot like a normal executable section but it has to specify the test-suite type. Currently only exitcode-stdio-1.0 is supported: test-suite test-threads type:exitcode-stdio-1.0 main-is: test.hs build-depends: ... To run the test-suite you first need to configure it: $ cabal configure --enable-tests then build it: $ cabal build then run it: $ cabal test Running 1 test suites... Test suite test-threads: RUNNING... Test suite test-threads: PASS Test suite logged to: dist/test/threads-0.4-test-threads.log 1 of 1 test suites (1 of 1 test cases) passed. Good luck, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Automated tests with cabal
On Thu, Mar 10, 2011 at 10:06 AM, Bas van Dijk v.dijk@gmail.com wrote: On 10 March 2011 08:12, Hauschild, Klaus (EXT) klaus.hauschild@siemens.com wrote: Hi Haskellers, I read about the cabal features for running test code from Setup.hs with defaultMainWithHooks. I'm looking for more generic code that allows me to place any haskell in a subdirectory test or so and cabal test will run this test without any modification of my Setup.hs. Is there a possibility? There is. The just released Cabal- 1.10.1.0 and cabal-install-0.10.2 have support for test-suites. The documentation is not online yet so here's an example from my threads package: You can find the docs here: http://www.haskell.org/cabal/release/cabal-1.10.1.0/doc/users-guide/#test-suites These are not yet the default docs (i.e. the docs linked from the Cabal home page) but will likely be soon. Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom monad using ST
In practice if you want to actually _use_ ST you'll find you'll need to let the world escape into your type. Otherwise you won't be able to create and pass around any STRefs or arrays and use them later. The universal quantification inside of MyST's definition will keep you from holding on to them. Okay, what you are saying is that two MyST action declared separately will not be compatible, right? I have another problem. One of my goal is to be able to alter an STRef when it is accessed. To do so, I use the following type: STRef s (ST s a). So the actual variable 'a' contained by my STRef is wrapped inside an ST action which goal is to modify the STRef and then return the value of type 'a'. My problem is that the STRef is not modfied, it always returns the same value. Example of this with IORefs, it is simpler to test: selfAlteringRef :: Int - IO (IORef (IO Int)) selfAlteringRef init = mfix $ \ref - newIORef $ do writeIORef ref (return 0) return init 2011/3/10 Edward Kmett ekm...@gmail.com On Wed, Mar 9, 2011 at 6:21 PM, Yves Parès limestr...@gmail.com wrote: Well, I want to hide the fact that I'm using ST, so if I can hide the existential type 's' it is better. In practice if you want to actually _use_ ST you'll find you'll need to let the world escape into your type. Otherwise you won't be able to create and pass around any STRefs or arrays and use them later. The universal quantification inside of MyST's definition will keep you from holding on to them. BTW, does someone know why the ST default implementation (the one exposed by Control.Monad.ST) is strict, whereas those of State et Writer are lazy? Mostly because of the principle of least surprise. It makes it act more like IO. -Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IPv6 issues for (code|community).haskell.org?
Erlend Hamberg wrote: When I wanted to get the newest xmonad code from darcs today¹ it was really, really slow... Being on an IPv6 network, and having been burnt by similar problems before, I tried adding IPv4 address for code.haskell.org in /etc/hosts... This fixed the issue ...Connecting to code.haskell.org in a Web browser also takes minutes, while e.g. http://ipv6.google.com/ works perfectly. Thanks for the report. I submitted a ticket for this. -Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] Linker flags for foreign export.
On 10 March 2011 04:04, Jason Dusek jason.du...@gmail.com wrote: I'm trying to hew relatively close to Duncan Coutts' blog posting in working through this; so I have different code and a new Makefile: Starting with your code I've managed to make it work (OS X 10.6, GHC 7). The Makefile is: loadfoo: loadfoo.c gcc -arch i386 loadfoo.c -o loadfoo libfoo.dynamic-dynamic.so: Foo.hs fooinit.c ghc -fPIC -c fooinit.c ghc --make -dynamic -fPIC -c Foo.hs ghc -shared -dynamic -o libfoo.dynamic-dynamic.so \ Foo.o Foo_stub.o fooinit.o \ -lHSrts_debug-ghc7.0.1.20101215 test: loadfoo libfoo.dynamic-dynamic.so ./loadfoo libfoo.dynamic-dynamic.so (I have to build loadfoo in 32-bit mode because GHC generates 32-bit code on OS X). The fact that we supply the RTS to the GHC link line is important because the shared library would not otherwise link against any particular RTS - in the normal course of things, GHC only decides on the RTS when linking the final executable. I'm linking against the debug RTS there but it should work with the normal one too - I just used the debug version to work out why I got a bus error upon load.. .. and the reason was that your fooinit.c was buggy - that probably account for the crashes you were seeing. The problem is that hs_init takes a *pointer to* argc and argv, not argc and argv directly. You supplied 0 for both of these so GHC died when it tried to dereference them. My new fooinit.c (that works) is as follows: #include HsFFI.h extern void __stginit_Foo(void); static void Foo_init (void) __attribute__ ((constructor)); void Foo_init (void) { char *arg1 = fake-main; char *argv[1] = { arg1 }; char **argv_p = argv; char ***pargv_p = argv_p; int argc = sizeof(argv) / sizeof(char *); hs_init(argc, pargv_p); hs_add_root(__stginit_Foo); } (Apologies for the extreme ugliness, it's been so long since I wrote C in anger the chain of initializers is the only way I could get this to build without a GCC warning about casts between different pointer types). I tested it with this Foo.hs: {-# LANGUAGE ForeignFunctionInterface #-} module Foo where import Foreign.C foreign export ccall foo:: CInt - CInt foo :: CInt - CInt foo = (+1) And a change to loadfoo.c that actually tries to calls foo: printf( %s\n, symbol lookup okay); + printf(%d\n, foo(1336)); } else { (You need int (*foo)(int) = dlsym(dl, foo) as well) The output is 1337 as expected. Cheers, Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Update Cabal
Hallo, I'm using Haskell Platform 2010.2.0.0 on a Windows XP machine. This haskell platform includes cabal-1.8.0.6. Now I want to update cabal by cabal install cabal. Installation works well. Call like runhaskell ./Setup.hs will use the updatetd cabal-1.10.0.0. But cabal --version says still 1.8.0.6 and I have to re-configure. How I update cabal in my current Haskel Platform? Thanks Klaus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Update Cabal
On Thu, Mar 10, 2011 at 11:27 AM, Hauschild, Klaus (EXT) klaus.hauschild@siemens.com wrote: Hallo, I'm using Haskell Platform 2010.2.0.0 on a Windows XP machine. This haskell platform includes cabal-1.8.0.6. Now I want to update cabal by cabal install cabal. Installation works well. Call like runhaskell ./Setup.hs will use the updatetd cabal-1.10.0.0. But cabal --version says still 1.8.0.6 and I have to re-configure. How I update cabal in my current Haskel Platform? cabal install cabal-install will not install the latest version of cabal-install due to a setting on Hackage (i.e. Duncan probably want to wait before automatically changing everyone over). You need to give the exact version: cabal install cabal-install-0.10.2 Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Update Cabal
Hi Johan, Thank you for the tip. After a tiny manupulation at my PATH variable it works. -Ursprüngliche Nachricht- Von: Johan Tibell [mailto:johan.tib...@gmail.com] Gesendet: Donnerstag, 10. März 2011 11:39 An: Hauschild, Klaus (EXT) Cc: haskell-cafe@haskell.org Betreff: Re: [Haskell-cafe] Update Cabal On Thu, Mar 10, 2011 at 11:27 AM, Hauschild, Klaus (EXT) klaus.hauschild@siemens.com wrote: Hallo, I'm using Haskell Platform 2010.2.0.0 on a Windows XP machine. This haskell platform includes cabal-1.8.0.6. Now I want to update cabal by cabal install cabal. Installation works well. Call like runhaskell ./Setup.hs will use the updatetd cabal-1.10.0.0. But cabal --version says still 1.8.0.6 and I have to re-configure. How I update cabal in my current Haskel Platform? cabal install cabal-install will not install the latest version of cabal-install due to a setting on Hackage (i.e. Duncan probably want to wait before automatically changing everyone over). You need to give the exact version: cabal install cabal-install-0.10.2 Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Update Cabal
What are the arguments for updating? Are you using ghc-7.0.2? Wait for Haskell Platform 2011.2.0.0 that will be based on cabal-install-0.10.2! Cheers Christian Am 10.03.2011 11:27, schrieb Hauschild, Klaus (EXT): Hallo, I'm using Haskell Platform 2010.2.0.0 on a Windows XP machine. This haskell platform includes cabal-1.8.0.6. Now I want to update cabal by cabal install cabal. Installation works well. Call like runhaskell ./Setup.hs will use the updatetd cabal-1.10.0.0. But cabal --version says still 1.8.0.6 and I have to re-configure. How I update cabal in my current Haskel Platform? Thanks Klaus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tagless interpreter, expression problem and zipper
This is already an improvement to my current code. But I am not entirely satisfied. I can pick and choose which structures to use in my terms but the context type is still an ordinary data type. Each module which extends the expression language with new structures needs to define a complicated context type. But the context type does not have to be complicated. There is no rule mandating the single context for any expression. For different sorts of processing, one may define suitable contexts, containing only the needed data. The example from the earlier message had to do something special for a literal that is the left immediate child of Add whose brother has specific value. That example requires a simple context. Here is the complete code, a small simplification of the code in the previous message. class Lit r where lit :: Integer - r class Add r where add :: r - r - r instance Lit Integer where lit = fromInteger instance Add Integer where add = (+) instance Lit String where lit = show instance Add String where add x y = ( ++ x ++ + ++ y ++ ) data AddLCtx r = AddL r | NotAddL instance (Add r, Add s) = Add (AddLCtx s - r, s) where add (xa, xb) (ya, yb) = ( \c - add (xa (AddL yb)) (ya NotAddL) , add xb yb ) -- Silly interpreter, version 2.0 instance Lit (AddLCtx Integer - String, Integer) where lit n = ( \c - case c of AddL 3 - Foo! _ - lit n , lit n ) t1 :: (Lit r, Add r) = r t1 = lit 2 `add` lit 3 bar = let (f, x) = t1 :: (AddLCtx Integer - String, Integer) in f NotAddL -- (Foo! + 3) Later on, we add multiplication. class Mul r where mul :: r - r - r instance Mul Integer where mul = (*) instance Mul String where mul x y = ( ++ x ++ * ++ y ++ ) We extend the Ctx interpreter for Mul, assuming AddLCtx meant the immediate left child of the Addition. If a left descendant was meant, the mul rule below should propagate the context rather than override it. instance (Mul r, Mul s) = Mul (AddLCtx s - r, s) where mul (xa, xb) (ya, yb) = ( \c - mul (xa NotAddL) (ya NotAddL) , mul xb yb ) t2 :: (Lit r, Add r, Mul r) = r t2 = (lit 2 `add` lit 3) `mul` (lit 4 `mul` (lit 5 `add` lit 3)) bar' = let (f, x) = t2 :: (AddLCtx Integer - String, Integer) in f NotAddL -- ((Foo! + 3) * (4 * (Foo! + 3))) Let's implement the example in the original message, and do something special at the left immediate child of addition whose brother is so and so and whose parent context is the left child of multiplication. We define the context that suits the problem, tracking if we are the left child of multiplication and if we are the left child of addition that is the left child of multiplication. It is easier done than said. data AddML r = AddML r | MulL | NotAddML instance (Add r, Add s) = Add (AddML s - r, s) where add (xa, xb) (ya, yb) = ( \c - (case c of MulL - add (xa (AddML yb)) (ya NotAddML) _ - add (xa NotAddML) (ya NotAddML)) , add xb yb ) instance (Mul s, Mul r) = Mul (AddML s - r, s) where mul (xa, xb) (ya, yb) = (\c - mul (xa MulL) (ya NotAddML), mul xb yb) The original example: instance Lit (AddML Integer - String, Integer) where lit n = ( \c - case c of AddML 3 - FooM! _ - lit n , lit n ) bar'' = let (f, x) = t2 :: (AddML Integer - String, Integer) in f NotAddML -- ((FooM! + 3) * (4 * (5 + 3))) The fully safe and explicit Typeable in http://okmij.org/ftp/tagless-final/course/Typ.hs shows example of defining many interpreters with many contexts. It was the tough problem though -- the first example showing how to compare to tagless-final terms for equality. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Convert a function to a string of operators?
Will methods explained here work for boolean expressions? The convenience of defining using specialised datatypes for serialising numeric operations comes from Num being a typeclass. This is not the case for Bool: Prelude :info Num class (Eq a, Show a) = Num a where (+) :: a - a - a ... -- Defined in GHC.Num Prelude :info Bool data Bool = False | True-- Defined in GHC.Bool Is there a way to extract parameter names from function definition to use them in Show instance? Or should I just use same names everywhere? The only kind of introspection I know comes from Template Haskell, but I'm sure there are other methods that I'm not aware of available. On Sun, Mar 6, 2011 at 7:28 AM, Evgeny Grablyk evgeny.grab...@gmail.com wrote: Many thanks for your help! Seems to be what I need. Two more related questions: Will methods explained here work for boolean expressions? Is there a way to extract parameter names from function definition to use them in Show instance? Or should I just use same names everywhere? In case that helps, here's the code I need to convert (the code in where part of solveScheme): http://npaste.de/aKY3cn0xZf/ -- Evgeny ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell mail server fail?
On Thursday 10 March 2011 07:24:45 you wrote: Like Kenneth Hoste, I haven't been receiving mails from haskell-cafe@ nor libraries@ for a few days to a week now. What is the status of the mailing lists? (Please CC me off-list, for obvious reasons) Like David, I receive posts for both lists. I'm not familiar with e-mail protocols, but does the best guess in Received-SPF: pass (google.com: best guess record for domain of haskell- cafe-boun...@haskell.org designates 78.46.100.180 as permitted sender) client-ip=78.46.100.180; indicate a possible problem? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Updates in the monadic regions family
In regions-0.9 I removed support for forking threads because it allowed you to use a closed handle in a forked thread. Unfortunately I just realized that it's still possible to fork threads in a region. The reason is that I've derived a MonadControlIO instance for RegionT which enables you to use forkIO as demonstrated by the following program: - {-# LANGUAGE UnicodeSyntax, NoImplicitPrelude, KindSignatures #-} module Main where -- from base: import Data.Function ( ($) ) import Control.Concurrent ( ThreadId, forkIO, threadDelay ) import Control.Monad ( (=), liftM, void ) import System.IO ( IO ) -- from transformers: import Control.Monad.IO.Class ( liftIO ) -- from regions: import Control.Monad.Trans.Region ( RegionT, runRegionT ) -- from safer-file-handles: import System.IO.SaferFileHandles ( openFile , IOMode(ReadMode) , hGetContents , putStrLn ) -- from pathtype: import System.Path.Posix ( asAbsFile ) -- from monad-control: import Control.Exception.Control ( mask_ ) import Control.Monad.IO.Control ( MonadControlIO, liftControlIO ) main ∷ IO () main = do runRegionT region threadDelay 150 region ∷ MonadControlIO pr ⇒ RegionT s pr () region = do putStrLn Running region h ← openFile (asAbsFile /etc/passwd) ReadMode _ ← liftForkIO $ do putStrLn Forked region liftIO $ threadDelay 100 hGetContents h = putStrLn liftIO $ threadDelay 50 putStrLn Exiting region liftForkIO ∷ MonadControlIO m ⇒ m α → m ThreadId liftForkIO m = liftControlIO $ \runInIO → forkIO $ void $ runInIO m - Executing main yields the following error: main Running region Forked region Exiting region interactive: /etc/passwd: hGetContents: illegal operation (handle is closed) I think the only solution is to drop the derived MonadControlIO and MonadTransControl instances. Unfortunately the packages that use regions require this instance because they need to use mask_ when opening resources. Here an example from safer-file-handles: openFile ∷ (MonadControlIO pr, AbsRelClass ar) ⇒ FilePath ar → IOMode ioMode → RegionT s pr (RegionalFileHandle ioMode (RegionT s pr)) openFile = openNormal E.openFile openNormal open = \filePath ioMode → mask_ $ do h ← liftIO $ open (getPathString filePath) ioMode ch ← onExit $ sanitizeIOError $ hClose h return $ RegionalFileHandle h ch I guess I have to solve this by providing a custom mask_ function or using MonadCatchIO-transformers as I did before. I'm going to think about the best solution. In the mean time just don't use something like liftForkIO. Regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ContT and ST stack
Dear list, I have the following (simplified) piece of code: find :: Int - [Int] find i = runST . (`runContT` return) $ callCC $ \escape - do return [] which used to compile correctly under GHC 6.12.3. Now that I've switched to 7.0.2 it gets rejected with the following error: Couldn't match expected type `forall s. ST s c0' with actual type `m0 r0' Expected type: ContT r0 m0 a0 - forall s. ST s c0 Actual type: ContT r0 m0 a0 - m0 r0 In the second argument of `(.)', namely `(`runContT` return)' In the expression: runST . (`runContT` return) I'm a little bit lost at what exactly is the problem. Anyone can suggest a solution? Thanks! AB ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ContT and ST stack
On Thursday 10 March 2011 14:18:24, Anakim Border wrote: Dear list, I have the following (simplified) piece of code: find :: Int - [Int] find i = runST . (`runContT` return) $ callCC $ \escape - do return [] which used to compile correctly under GHC 6.12.3. Now that I've switched to 7.0.2 it gets rejected with the following error: Couldn't match expected type `forall s. ST s c0' with actual type `m0 r0' Expected type: ContT r0 m0 a0 - forall s. ST s c0 Actual type: ContT r0 m0 a0 - m0 r0 In the second argument of `(.)', namely `(`runContT` return)' In the expression: runST . (`runContT` return) I'm a little bit lost at what exactly is the problem. If memory serves correctly, it's impredicative polymorphism. The type of (.), (b - c) - (a - b) - a - c, can't handle (x - forall s. ST s [Int]) Previously there was an implementation of impredicative polymorphism which allowed GHC to handle that construct, but that has been removed (because it was unsatisfactory), so GHC 7 doesn't compile that anymore. Anyone can suggest a solution? Parentheses. find i = runST ((`runContT` return) $ callCC $ \escape - do return []) Thanks! AB ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ContT and ST stack
On 10 March 2011 14:47, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: If memory serves correctly, it's impredicative polymorphism. Indeed. For example the following also doesn't type check in GHC-7: foo :: (forall s. ST s a) - a foo st = ($) runST st Surprisingly the following does: foo :: (forall s. ST s a) - a foo st = runST $ st Because GHC contains a special rule for infix $. Also see: http://article.gmane.org/gmane.comp.lang.haskell.glasgow.user/19152 Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ContT and ST stack
On Thursday 10 March 2011 17:15:29, Bas van Dijk wrote: On 10 March 2011 14:47, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: If memory serves correctly, it's impredicative polymorphism. Indeed. For example the following also doesn't type check in GHC-7: foo :: (forall s. ST s a) - a foo st = ($) runST st Surprisingly the following does: foo :: (forall s. ST s a) - a foo st = runST $ st Because GHC contains a special rule for infix $. Also see: http://article.gmane.org/gmane.comp.lang.haskell.glasgow.user/19152 Bas Bedankt. I sort of knew there was a special case for ($) because runST $ do ... works, but not exactly what was handled. So until I forget, I now know it's infix ($) and only that. Cheers, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why don't my OS threads terminate?
On 28/02/11 15:59, Bas van Dijk wrote: On 25 February 2011 19:10, Bas van Dijkv.dijk@gmail.com wrote: On 25 February 2011 18:27, sclvs.clo...@gmail.com wrote: Bas van Dijk-2 wrote: I believe the OS threads are created by my levmar library. This library uses bindings-levmar[4] which is a binding to a C library. bindings-levmar uses safe FFI calls because the levmar C procedures are reentrant (they need to call back into Haskell to execute the model function). I believe the RTS creates an OS thread for each safe FFI call. Sounds like #4262: http://hackage.haskell.org/trac/ghc/ticket/4262 (Should be fixed in head) That looks exactly like my problem. I will try it out with ghc head on monday. In ghc-HEAD (7.1.20110227) the bug is fixed, great! The bug still appears in ghc-7.0.2-rc2, so I assume the patch in #4262 was not merged in that release. Will it be merged into the upcoming ghc-7.0.2? I'm slightly worried by this. #4262 was not an OS thread leak, but rather that when the program needs fewer OS threads we weren't returning the surplus OS threads back to the system. #4262 doesn't make programs use an ever-increasing number of OS threads. It's an optimisation rather than a bug, which is why we didn't merge the patch into the 7.0 branch. So I'm concerned because the symptom you describe sounds more like a leak. #4850 could have caused it, but the fix for that was merged into 7.0.2. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel Haskell stories
From: Simon Peyton-Jones simo...@microsoft.com Friends I'm giving a talk at a developer conference in London on Friday 18th, about parallel programming in Haskell. http://skillsmatter.com/event/scala/functionalpx-2011/ad-1382 I know that some of you have been using Haskell for parallel or concurrent programming quite a bit, so this email is just to ask could you contribute a little vignette or story about using Haskell in a *parallel/concurrent* application that I could use to illustrate my talk? I have a physical-model-based audio synthesis application I wanted to convert from an off-line renderer into a real-time engine. I decided upon a concurrent architecture with an interface thread, an engine thread, and an output thread, using STM for communication. It only took a couple hours to make the conversion, most of which was spent modifying the synthesis to work in blocks instead of a single run. I'm particularly happy with this snippet, where the engine collects input from the interface thread: readStrikeVar = do ct - getCPUTime atomically $ rsv' ct `orElse` return [] -- if the read fails, return an empty list because we can't afford to wait. -- the strikes will eventually catch up... rsv' ct = do strikes - readTVar tstrikes let carry = map (updateCarry blockdur) $ filter carryOver strikes writeTVar tstrikes carry writeTVar tsync ct return (reverse strikes) This code is the most complicated part of the communication scheme, nearly everything else is at the level of readTVarIO. A nice feature is that the engine doesn't block waiting for the interface. If the transaction fails because the interface is updating the TVar, the engine moves ahead and can catch up later. On my dual-core macbook, performance is perhaps slightly disappointing compared to the offline renderer which is single-threaded and not parallelized. With one simulation the offline renderer will generate 5 seconds of audio in about 3.3seconds at 100% CPU usage, giving me the equivalent of 66% CPU over 5 seconds. The realtime renderer consistently occupies about 171% CPU for the same simulation. A different simulation has a runtime of 4.4 seconds and realtime usage of 191%. Of course there's going to be some overhead, but I hope to improve this by changing the way data is fed to the engine to a TChan, and also running threadscope to make sure threads yield at the proper times. Speaking of which, threadscope is an awesome tool and deserves a mention. John L. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ContT and ST stack
Why has the operator (.) troubles with a type like (forall s. ST s a)? Why can't it match the type 'b' in (.) definition? 2011/3/10 Daniel Fischer daniel.is.fisc...@googlemail.com On Thursday 10 March 2011 14:18:24, Anakim Border wrote: Dear list, I have the following (simplified) piece of code: find :: Int - [Int] find i = runST . (`runContT` return) $ callCC $ \escape - do return [] which used to compile correctly under GHC 6.12.3. Now that I've switched to 7.0.2 it gets rejected with the following error: Couldn't match expected type `forall s. ST s c0' with actual type `m0 r0' Expected type: ContT r0 m0 a0 - forall s. ST s c0 Actual type: ContT r0 m0 a0 - m0 r0 In the second argument of `(.)', namely `(`runContT` return)' In the expression: runST . (`runContT` return) I'm a little bit lost at what exactly is the problem. If memory serves correctly, it's impredicative polymorphism. The type of (.), (b - c) - (a - b) - a - c, can't handle (x - forall s. ST s [Int]) Previously there was an implementation of impredicative polymorphism which allowed GHC to handle that construct, but that has been removed (because it was unsatisfactory), so GHC 7 doesn't compile that anymore. Anyone can suggest a solution? Parentheses. find i = runST ((`runContT` return) $ callCC $ \escape - do return []) Thanks! AB ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ContT and ST stack
On 10 March 2011 18:24, Yves Parès limestr...@gmail.com wrote: Why has the operator (.) troubles with a type like (forall s. ST s a)? Why can't it match the type 'b' in (.) definition? As explained by the email from SPJ that I linked to, instantiating a type variable (like 'b') with a polymorphic type (like 'forall s. ST s a' ) is called impredicative polymorphism. Since GHC-7 this is not supported any more because it was to complicated. Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why don't my OS threads terminate?
On 10 March 2011 18:11, Simon Marlow marlo...@gmail.com wrote: On 28/02/11 15:59, Bas van Dijk wrote: On 25 February 2011 19:10, Bas van Dijkv.dijk@gmail.com wrote: On 25 February 2011 18:27, sclvs.clo...@gmail.com wrote: Bas van Dijk-2 wrote: I believe the OS threads are created by my levmar library. This library uses bindings-levmar[4] which is a binding to a C library. bindings-levmar uses safe FFI calls because the levmar C procedures are reentrant (they need to call back into Haskell to execute the model function). I believe the RTS creates an OS thread for each safe FFI call. Sounds like #4262: http://hackage.haskell.org/trac/ghc/ticket/4262 (Should be fixed in head) That looks exactly like my problem. I will try it out with ghc head on monday. In ghc-HEAD (7.1.20110227) the bug is fixed, great! The bug still appears in ghc-7.0.2-rc2, so I assume the patch in #4262 was not merged in that release. Will it be merged into the upcoming ghc-7.0.2? I'm slightly worried by this. #4262 was not an OS thread leak, but rather that when the program needs fewer OS threads we weren't returning the surplus OS threads back to the system. #4262 doesn't make programs use an ever-increasing number of OS threads. It's an optimisation rather than a bug, which is why we didn't merge the patch into the 7.0 branch. So I'm concerned because the symptom you describe sounds more like a leak. #4850 could have caused it, but the fix for that was merged into 7.0.2. My bug is solved in 7.0.2. Regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Learn You a Haskell for Great Good - a few doubts
On 7 Mar 2011, at 23:38, Alexander Solla wrote: _|_ /= (_|_,_|_) (undefined, undefined) (*** Exception: Prelude.undefined That is as close to Haskell-equality as you can get for a proto-value that does not have an Eq instance. As a consequence of referential transparency, evaluation induces an equivalence relation. This implies that (_|_, _|_) = _|_ = (_|_, _|_). Surely the key thing is the '(' character which is produced immediately before the exception is encountered. I'd say that demonstrates that in GHC _|_ /= (_|_,_|_). --Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] possible bug for ghc 7 + xcode 4 on snow leopard?
Hi, I haven't installed XCode 4 yet, but the crt1.10.5.o is the c runtime file defining the symbol start which any program will be linked with being the programs real entry point. Disassembling crt1.10.5.o (for Leopard) and crt1.10.6.o (for Snow Leopard) reveals the very same code for the symbol start, but crt1.10.5.o additionally defines dyld_stub_binding_helper and __dyld_func_lookup. I think I read that XCode 4 is snow leopard+ only, therefore I guess crt1.10.5.o was deleted when you've install Xcode 4. Maybe a symbolic link ln -s crt1.10.6.o crt1.10.5.o in /usr/lib shall do just fine, but I will keep a copy of crt1.10.5.o before upgrading to Xcode 4 just in case and report any findings. - Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] possible bug for ghc 7 + xcode 4 on snow leopard?
Questions: 1. How did you install ghc-7? Using a binary package? The one for leopard or snow leopard? 2. Which compiler flags did you use? Does it work with another backend? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: Haskell Platform 2011.2 released!
We're pleased to announce the 2011.2 release of the Haskell Platform: a single, standard Haskell distribution for everyone. Download the Haskell Platform 2011.2.0.0: http://haskell.org/platform/ The specification, along with installers (including Windows, Apple and Unix installers for a full Haskell environment) are available. The Haskell Platform is a single, standard Haskell distribution for every system, in the form of a blessed library and tool suite for Haskell distilled from the thousands of libraries on Hackage, along with installers for a wide variety of systems. It saves developers work picking and choosing the best Haskell libraries and tools to use for a task. When you install the Haskell Platform, you get the latest stable compiler, an expanded set of core libraries, additional development tools, and cabal-install – so you can download anything else you need from Hackage. This release ships with GHC 7. What you get is specified here: http://hackage.haskell.org/platform/contents.html Thanks! -- The Platform Infrastructure Team P.S. a big thanks to Mark Lentczner and Mikhail Glushenkov who built the Mac and Windows installers! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: cinvoke 0.1 released
On Wed, Mar 09, 2011 at 05:50:12PM +0100, Gábor Lehel wrote: On Wed, Mar 9, 2011 at 5:26 PM, Remi Turk rt...@science.uva.nl wrote: Count on it having at least an order of magnitude more overhead. I did some simple test of calling the following three trivial functions (with constant arguments, and ignoring the return values, 2M times) and got the following timings: int blub0() { return 42; } int blub1(int a) { return 42; } int blub5(int a, int b, int c, int d, int e) { return 42; } Unsafe FFI Safe FFI Safe dynamic FFI CInvoke blub0 0.03 0.19 0.20 1.62 blub1 0.03 0.20 0.20 2.44 blub5 0.04 0.20 0.20 4.35 It's not that bad for functions that actually (try to) do something though. For example, trying to remove a non-existent file: unlink 3.06 3.04 3.27 7.15 If I remember correctly, libffi was slightly faster, but mostly thanks to the fact that I didn't make it exception safe yet. So if you care about performance and are able to directly use the FFI, you clearly should. That describes my situation. Thanks! For the record, what units were your measurements in? (I notice that the overhead of safe FFI calls seems to be pretty smallish, which is also quite heartening.) Everything is in seconds. So for example, 2 million unsafe calls to blub0 take 0.03 seconds: ~15ns or ~42 cycles per call (including replicateM_ overhead). I just noticed in my little non-scientific benchmark that the overhead for safe calls is significantly higher when compiling with -threaded: Unsafe FFI Safe FFI Safe dynamic FFI CInvoke blub0 0.04 0.36 0.35 2.27 blub1 0.05 0.36 0.36 3.52 blub5 0.05 0.37 0.37 5.72 unlink 3.26 3.21 3.56 8.41 Groeten, Remi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why don't my OS threads terminate?
On 10/03/11 18:20, Bas van Dijk wrote: On 10 March 2011 18:11, Simon Marlowmarlo...@gmail.com wrote: On 28/02/11 15:59, Bas van Dijk wrote: On 25 February 2011 19:10, Bas van Dijkv.dijk@gmail.comwrote: On 25 February 2011 18:27, sclvs.clo...@gmail.comwrote: Bas van Dijk-2 wrote: I believe the OS threads are created by my levmar library. This library uses bindings-levmar[4] which is a binding to a C library. bindings-levmar uses safe FFI calls because the levmar C procedures are reentrant (they need to call back into Haskell to execute the model function). I believe the RTS creates an OS thread for each safe FFI call. Sounds like #4262: http://hackage.haskell.org/trac/ghc/ticket/4262 (Should be fixed in head) That looks exactly like my problem. I will try it out with ghc head on monday. In ghc-HEAD (7.1.20110227) the bug is fixed, great! The bug still appears in ghc-7.0.2-rc2, so I assume the patch in #4262 was not merged in that release. Will it be merged into the upcoming ghc-7.0.2? I'm slightly worried by this. #4262 was not an OS thread leak, but rather that when the program needs fewer OS threads we weren't returning the surplus OS threads back to the system. #4262 doesn't make programs use an ever-increasing number of OS threads. It's an optimisation rather than a bug, which is why we didn't merge the patch into the 7.0 branch. So I'm concerned because the symptom you describe sounds more like a leak. #4850 could have caused it, but the fix for that was merged into 7.0.2. My bug is solved in 7.0.2. Ah great, thanks for testing. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] possible bug for ghc 7 + xcode 4 on snow leopard?
to answer the question of the other poster, ghc 7.0.2 packaged installer, 64 bit build Jurrien, I wound up doing something similar, namely just wholesale copying the 10.5 sdk into the sdks folder. i'm still curious why this problem even exists! 2011/3/10 Jurriën Stutterheim j.stutterh...@students.uu.nl I solved it by making a symlink from /Developer/SDKs/MacOSX10.6.sdk to /Developer/SDKs/MacOSX10.5.sdk (which is missing with XCode 4). So far it seems to work :) Jurriën On 10 Mar, 2011, at 06:53 , Carter Schonwald wrote: after experimenting by just naively moving the old Developer directory back to its original location preceding the installation of xcode 4, everything builds properly now. still, this is not a reasonable long term solution. Any ideas about how this might be fixed? On Thu, Mar 10, 2011 at 12:33 AM, Carter Schonwald carter.schonw...@gmail.com wrote: Hey All, As of installing xcode 4 earlier today, i'm getting errors of the form ld: library not found for -lcrt1.10.5.o collect2: ld returned 1 exit status for any haskell code that invokes ld in its cabal install process. 1) is this related to some problem in xcode / what the haskell code defaults to linking to? 2) is this something completely unrelated? thanks! -Carter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel Haskell stories
On Wed, Mar 9, 2011 at 11:18 AM, Simon Peyton-Jones simo...@microsoft.com wrote: could you contribute a little vignette or story about using Haskell in a *parallel/concurrent* application that I could use to illustrate my talk? The Cryptographic Protocol Shapes Analyzer (CPSA) attempts to enumerate all essentially different executions possible for a cryptographic protocol. At each step in the analysis, it infers what else must have happened based on an incomplete description of an execution. The steps form a derivation tree. If CPSA terminates on its input, each leaf of the derivation tree is a complete description of some executions, and the leaves collectively enumerate all possible executions. It is crucial for performance reasons that CPSA does not compute a tree, but instead computes a directed acrylic graph (DAG). To do so, it must identify pairs of nodes in the derivation that are isomorphic. For large problems, the isomorphism check dominates all other computation during the analysis. So how does CPSA use parallelism? CPSA expands the derivation DAG in a breadth-first order. For each node at the current level, the program performs the isomorphism check on all nodes higher up in the DAG in one thread. All threads then join, and in the main thread, the intra-level isomorphism checks are performed. It's that simple. At the code level, all that is done is replace one map call with a parallelized version of map that I saw in one of your papers: #if defined HAVE_PAR parMap :: (a - b) - [a] - [b] parMap _ [] = [] parMap f (x:xs) = par y (pseq ys (y:ys)) where y = f x ys = parMap f xs Performance varies depending on the shape of the DAG. A wide bushy DAG makes better use of more processors. I have found one can often get a speedup of three on a quad processor machine. Of course performance also varies depending on the version of GHC runtime in use. A speedup of three may not sound like much, but on some problems, CPSA takes twenty-four hours to run on a single core. Parallelizing CPSA was not as simple as I made it sound. I had the restructure the sequential description of the algorithm to expose the parallelism to the runtime, and the algorithm became less obvious. Of course, this cost is well worth it. John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel Haskell stories
On Thu, Mar 10, 2011 at 6:04 PM, John D. Ramsdell ramsde...@gmail.com wrote: At the code level, all that is done is replace one map call with a parallelized version of map that I saw in one of your papers: #if defined HAVE_PAR parMap :: (a - b) - [a] - [b] parMap _ [] = [] Opps. Please delete the #if line. In the actual code, I have preserved the ability to compile CPSA using GHC 6.8 by using the C preprocessor as follows: #if defined HAVE_PAR parMap :: (a - b) - [a] - [b] parMap _ [] = [] parMap f (x:xs) = par y (pseq ys (y:ys)) where y = f x ys = parMap f xs #else parMap :: (a - b) - [a] - [b] parMap = map #endif John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel Haskell stories
On Wed, Mar 9, 2011 at 17:18, Simon Peyton-Jones simo...@microsoft.com wrote: could you contribute a little vignette or story about using Haskell in a *parallel/concurrent* application that I could use to illustrate my talk? Combinatorrent is a BitTorrent client written in Haskell, based upon the same ideas as Etorrent, a BitTorrent client written in Haskell. Combinatorrent uses an aggressive forkIO-style on top of STM Transactional channels for communication. The client implements the official protocol and several extensions in far fewer lines than contemporary clients, usually a factor of 4-5 in souce code lines. Four advantages present in Haskell (There is some overlap with Erlang here): * Spawning a new lightweight thread is extremely cheap. It encourages a coding style where you just spawn another process to do work for you rather than a style where you try, emphasis try, to harness a few OS threads. * Immutability and Persistence of the data plays a big role in getting the program simple. You can just send off a large data structure to another thread without having to worry that the other thread destructively destroys invariants. This in effect yields an effective way to use persistence to give quick caching of data in other threads, fast responsibility handover and so on. * Protocol parsing is a special case of an Applicative Functor. This yields protocol parsers that reads like specifications in RFCs, and still they run extremely fast. * We do configuration of BitTorrent extensions by having each extension be an element in a Monoid and then use function composition as the monoid-operation to chain together extensions at hook-points. This yields a very simple and very effective way to dynamically configure each peer we communicate with with the peers supported extensions. It also decouples the extension-code neatly from the main code. All in all, I was quite happy with using Haskell, even though I am currently more focusing on my Erlang client. I have read code in C++, C and Java clients, and it is scary how much work they have to do in order to achieve just part of the work. (Performance could be better, but this is GHC612 without the new IO-manager measurements - and I expect it to have deep impact). -- J. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] hsc2hs not figuring out #include paths?
I'm trying to write some bindings using hsc2hs. At the top of my .hsc file, I have #include jack/types.h #include jack/jack.h When I compile a .c file with just these two lines in gcc, it works fine (the jack directory is in /usr/local/include). When I try to run hsc2hs, it complains that it cannot find the header files. Any ideas? How do I set the include path (via cabal or just in hsc2hs) for hsc2hs? -- Edward Amsden Student Computer Science Rochester Institute of Technology www.edwardamsden.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Help with how to concatenate with own datatypes
Hi, I´m doing a project in haskell and I need to define an operator that concatenate some own defined data types, just like the operator ++ does for lists. I don´t see how to define the operator recursively since this adding function (:) doesn´t work on my own data types. This is my code: data Allele = Aone | Atwo deriving Show type Lifespan = Int data Population = Pop [(Allele,Allele,Lifespan)] deriving Show genepool :: Population genepool = Pop [] --can only concatenate 2 elements (+-) :: Population - Population - Population Pop [(a,b,c)] +- Pop [] = Pop [(a,b,c)] Pop [(a,b,c)] +- Pop [(d,e,f)] = Pop [(a,b,c),(d,e,f)] --and thats why this function goes non-exhaustive. gpinsertaoneaone :: Int - Int - Population gpinsertaoneaone 0 age = genepool gpinsertaoneaone n age = Pop [(Aone,Aone,70-age)] +- gpinsertaoneaone (n-1) age Thx for help and advice! -- View this message in context: http://haskell.1045720.n5.nabble.com/Help-with-how-to-concatenate-with-own-datatypes-tp3424433p3424433.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help with how to concatenate with own datatypes
On Thu, Mar 10, 2011 at 7:41 PM, eldavido eldavi...@hotmail.com wrote: Hi, I´m doing a project in haskell and I need to define an operator that concatenate some own defined data types, just like the operator ++ does for lists. I don´t see how to define the operator recursively since this adding function (:) doesn´t work on my own data types. This is my code: data Allele = Aone | Atwo deriving Show type Lifespan = Int data Population = Pop [(Allele,Allele,Lifespan)] deriving Show I don't know what precise behavior you want to model, but can you use the '++' operator in your definition? (Pop x) +- (Pop y) = Pop (x ++ y) Antoine genepool :: Population genepool = Pop [] --can only concatenate 2 elements (+-) :: Population - Population - Population Pop [(a,b,c)] +- Pop [] = Pop [(a,b,c)] Pop [(a,b,c)] +- Pop [(d,e,f)] = Pop [(a,b,c),(d,e,f)] --and thats why this function goes non-exhaustive. gpinsertaoneaone :: Int - Int - Population gpinsertaoneaone 0 age = genepool gpinsertaoneaone n age = Pop [(Aone,Aone,70-age)] +- gpinsertaoneaone (n-1) age Thx for help and advice! -- View this message in context: http://haskell.1045720.n5.nabble.com/Help-with-how-to-concatenate-with-own-datatypes-tp3424433p3424433.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe