[Haskell-cafe] IPv6 issues for (code|community).haskell.org?
Hi, When I wanted to get the newest xmonad code from darcs today¹ it was really, really slow. Running “host” revealed that code.haskell.org is an alias for community.haskell.org and that it has an IPv6 address associated with it. 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 in order to force the connection to happen over IPv4. This fixed the issue and “darcs get” now takes a few minutes. I just wanted to alert people in case the problem is at the server end. (And in case this isn’t just a temporary problem.) Connecting to code.haskell.org in a Web browser also takes minutes, while e.g. http://ipv6.google.com/ works perfectly. [1] With “darcs get http://code.haskell.org/xmonad” -- Erlend Hamberg ehamb...@gmail.com ___ 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
The Tagless final approach can do context-sensitive evaluation, using the well-known trick from the denotational semantics that explicating the context turns context-sensitive semantics to compositional. The trick isn't out of place given how much tagless-final approach is related to denotational semantics. The non-compositional processing has been discussed at length at lectures last year. Please see the explanation and the code at Non-compositionality: Fold-unlike processing http://okmij.org/ftp/tagless-final/course/course.html#non'compositionality Interestingly, one example FlatF.hs mentioned on the above page specifically talks about the context of being the left operand of the addition (the goal was to `flatten' additions, to re-associate them to the right). That is the same context as you are after, it seems. The detailed lecture notes will be eventually available. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Overlaping Parsec rules
Am 08.03.2011 13:50, schrieb Christian Maeder: Am 08.03.2011 13:35, schrieb Hauschild, Klaus (EXT): Hi Christian, Thank you for your help. Now the current version of Parse.hs (http://code.google.com/p/hgmltracer/source/browse/trunk/hGmlTracer/src/Gml/Parse.hs) works well for the test file fact.gml. spaces char end The idea is to call spaces _after_ every token. In other words spaces before char end is not needed. So the keyword parser should be extended by spaces and also the number, char, string, binder and identifier parsers. This is not necessary since you skip spaces after parseGml'. skip (A | B) is better than skip A | skip B. C. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Overlaping Parsec rules
Am 09.03.2011 14:44, schrieb Christian Maeder: Am 08.03.2011 13:50, schrieb Christian Maeder: Am 08.03.2011 13:35, schrieb Hauschild, Klaus (EXT): Hi Christian, Thank you for your help. Now the current version of Parse.hs (http://code.google.com/p/hgmltracer/source/browse/trunk/hGmlTracer/src/Gml/Parse.hs) works well for the test file fact.gml. spaces char end The idea is to call spaces _after_ every token. In other words spaces before char end is not needed. But in your top-level parser you may want to skip leading spaces and check for a final eof to ensure that everything was consumed. spaces liftM2 const parseList eof (Instead of liftM2 const the symbol * from Control.Applicative may be used: spaces * parseList * eof) I defined: infixl 1 () :: Monad m = m a - m b - m a () = liftM2 const and would use: spaces parseList eof C. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Platform 2011.2
code.haskell.org is the release repo code.galois.com is current development repo - Mark ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parallel Haskell stories
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 can rant all I like about the glories of Haskell, but I'm a biased witness. It's much more convincing if I can illustrate with true tales from the trenches. I'm interested in both parallelism and concurrency, so for example the success of Warp in using Concurrent Haskell is in scope. I can't say a lot about any one example, obviously, but what would be great would be - an idea of how Haskell helped (esp if you have a head to head comparison) - code snippets that illustrate how lovely it all is - brief performance indicators *Insight* is the key word. I don't just want to say Company X used Haskell to do Y because that doesn't convey any re-usable insights or ideas. What is the essence? I'll start writing in earnest on Monday 14th; the talk is on Friday. I have plenty to say already, so treat this as an opportunity not an obligation. But still, examples would be good! Do let me know if you have one. Simon ___ 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 Tue, Mar 08, 2011 at 01:01:58PM +0100, Gábor Lehel wrote: On Sun, Mar 6, 2011 at 2:38 PM, Remi Turk rt...@science.uva.nl wrote: Where? Hackage: http://hackage.haskell.org/package/cinvoke Cheers, Remi [1] http://www.nongnu.org/cinvoke/ Is there any information on how this (and libffi I guess) compare to GHC's FFI in terms of performance? Is it equivalent? Once you've loaded a function with loadSymbol and are cinvoking it with various arguments, versus a plain foreign import of the same. 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. (Also, I assume cinvoke corresponds to the FFI's 'unsafe' calls, i.e. if the function tries to call back into the GHC runtime then Bad Things will happen, and it'll block threads on the same 'Capability' if it runs too long?) Actually, it doesn't: Considering the rather large overhead of CInvoke itself, I just import everything 'safe'. Though to be honest I didn't actually test any callbacks into Haskell. Cheers, Remi ___ 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 9, 2011 at 5:26 PM, Remi Turk rt...@science.uva.nl wrote: On Tue, Mar 08, 2011 at 01:01:58PM +0100, Gábor Lehel wrote: On Sun, Mar 6, 2011 at 2:38 PM, Remi Turk rt...@science.uva.nl wrote: Where? Hackage: http://hackage.haskell.org/package/cinvoke Cheers, Remi [1] http://www.nongnu.org/cinvoke/ Is there any information on how this (and libffi I guess) compare to GHC's FFI in terms of performance? Is it equivalent? Once you've loaded a function with loadSymbol and are cinvoking it with various arguments, versus a plain foreign import of the same. 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.) (Also, I assume cinvoke corresponds to the FFI's 'unsafe' calls, i.e. if the function tries to call back into the GHC runtime then Bad Things will happen, and it'll block threads on the same 'Capability' if it runs too long?) Actually, it doesn't: Considering the rather large overhead of CInvoke itself, I just import everything 'safe'. Though to be honest I didn't actually test any callbacks into Haskell. Oh, yeah, it makes sense that the safety of the calls cinvoke makes would be same as the safety under which cinvoke itself is imported. Didn't think of that. Cheers, Remi -- Work is punishment for failing to procrastinate effectively. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel Haskell stories
On 9 March 2011 17:18, Simon Peyton-Jones simo...@microsoft.com wrote: I can't say a lot about any one example, obviously, but what would be great would be - an idea of how Haskell helped (esp if you have a head to head comparison) - code snippets that illustrate how lovely it all is - brief performance indicators *Insight* is the key word. I don't just want to say Company X used Haskell to do Y because that doesn't convey any re-usable insights or ideas. What is the essence? For what it's worth… (I imagine you're looking for more speed-intensive projects, but I like talking about Haskell, so here goes) my pet project IRCd called Hulk[1]. I whipped up a simple IRCd in an evening, and then the next day we (the dev team where I work[4]) were using it! Each client runs as a lightweight thread. The initial version used MVars all over the place, basically imperative, typical sloppy getting it done quickly code. I rewrote it a couple days later so that only the code that accepts connections and responds on the sockets is impure (100~ lines), and all the main code is totally pure (700~ lines), written in a monad stack of reader (connection information), writer (replies) and state (user details) (I abuse them[2]). I wrote about 500 lines of the pure stuff before even running it, and it just worked. There is one MVar in the project, that holds a pure value of all the state, this along with totally pure code, which has the obvious benefits; testability, a kind of transactional isolation. Some things (like checking against a SHA1 encrypted password file) require IO, so I have a MonadProvider class[3], with methods for *providing* values that will be impurely-acquired in the real server, but while testing I can provide my own values in a pure Reader or whatnot (HUnit and even QuickCheck spring to mind). One benefit, which didn't occur to me until asked about it, is that I didn't have to think much about choosing to have a separate thread per client because threads are so light-weight, my (Common Lisper) colleague was taken aback, being used to only expensive OS threads. The process been running for the past three weeks and we use it for all our dev discussion and for displaying things from feeds with rss2irc like commits, service events, support tickets, etc. Not bad for a few evenings of hacking! Insights: (1) It's nice and actually practical to make everything pure apart from the truly non-pure things, the monad of which can be parametrized. (2) Use of light-weight threads feels very natural, letting you think as if you're working in a single thread (with, e.g. blocking sockets), with no real cost. (3) Rapid prototyping in Haskell is actually very easy and effective. [1]: https://github.com/chrisdone/hulk [2]: class Monad m = MonadProvider m where providePreface :: m (Maybe String) provideMotd :: m (Maybe String) provideKey :: m String providePasswords :: m String [3]: I could stick all these in the StateT, but I think Reader and Writer are like nice, statically-enforced documentation. newtype IRC m a = IRC { runIRC :: ReaderT (UTCTime,Conn) (WriterT [Reply] (StateT Env m)) a } deriving (Monad ,Functor ,MonadWriter [Reply] ,MonadState Env ,MonadReader (UTCTime,Conn)) [4]: FWIW, the development section of CREATE-NET, a research centre in Italy. We are hiring Haskellers for application dev… ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Platform 2011.2
Also, due to reformatting code.haskell.org, the accounts were disabled for a while. On Wed, Mar 9, 2011 at 6:24 AM, Mark Lentczner mark.lentcz...@gmail.com wrote: code.haskell.org is the release repo code.galois.com is current development repo - Mark ___ 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
A couple of years ago, Lambda Lounge [1] a local group of language enthusiasts had a shootout [2] where you were supposed to implement a simple vending machine [3] that took coins and dispensed candy. With *very* little experience using Haskell I was able to implement a vending machine server [4] that wrapped its candy and change stock in a TVar so it took multiple concurrent requests and either dispensed change/candy or block if there wasn't any stock. I think that STM's ease of use impressed people. If you're thinking of running the code, please let me know and I'll get it working with a recent GHC. -deech [1] lambdalounge.org [2] http://lambdalounge.org/2009/05/05/may-meeting/ [3] http://stllambdalounge.files.wordpress.com/2009/03/vendingmachinespecification.pdf [4] http://patch-tag.com/r/deech2k/VendingMachine/snapshot/current/content/pretty/VendingMachine.hs On Wed, Mar 9, 2011 at 11:50 AM, Christopher Done chrisd...@googlemail.com wrote: On 9 March 2011 17:18, Simon Peyton-Jones simo...@microsoft.com wrote: I can't say a lot about any one example, obviously, but what would be great would be - an idea of how Haskell helped (esp if you have a head to head comparison) - code snippets that illustrate how lovely it all is - brief performance indicators *Insight* is the key word. I don't just want to say Company X used Haskell to do Y because that doesn't convey any re-usable insights or ideas. What is the essence? For what it's worth… (I imagine you're looking for more speed-intensive projects, but I like talking about Haskell, so here goes) my pet project IRCd called Hulk[1]. I whipped up a simple IRCd in an evening, and then the next day we (the dev team where I work[4]) were using it! Each client runs as a lightweight thread. The initial version used MVars all over the place, basically imperative, typical sloppy getting it done quickly code. I rewrote it a couple days later so that only the code that accepts connections and responds on the sockets is impure (100~ lines), and all the main code is totally pure (700~ lines), written in a monad stack of reader (connection information), writer (replies) and state (user details) (I abuse them[2]). I wrote about 500 lines of the pure stuff before even running it, and it just worked. There is one MVar in the project, that holds a pure value of all the state, this along with totally pure code, which has the obvious benefits; testability, a kind of transactional isolation. Some things (like checking against a SHA1 encrypted password file) require IO, so I have a MonadProvider class[3], with methods for providing values that will be impurely-acquired in the real server, but while testing I can provide my own values in a pure Reader or whatnot (HUnit and even QuickCheck spring to mind). One benefit, which didn't occur to me until asked about it, is that I didn't have to think much about choosing to have a separate thread per client because threads are so light-weight, my (Common Lisper) colleague was taken aback, being used to only expensive OS threads. The process been running for the past three weeks and we use it for all our dev discussion and for displaying things from feeds with rss2irc like commits, service events, support tickets, etc. Not bad for a few evenings of hacking! Insights: (1) It's nice and actually practical to make everything pure apart from the truly non-pure things, the monad of which can be parametrized. (2) Use of light-weight threads feels very natural, letting you think as if you're working in a single thread (with, e.g. blocking sockets), with no real cost. (3) Rapid prototyping in Haskell is actually very easy and effective. [1]: https://github.com/chrisdone/hulk [2]: class Monad m = MonadProvider m where providePreface :: m (Maybe String) provideMotd :: m (Maybe String) provideKey :: m String providePasswords :: m String [3]: I could stick all these in the StateT, but I think Reader and Writer are like nice, statically-enforced documentation. newtype IRC m a = IRC { runIRC :: ReaderT (UTCTime,Conn) (WriterT [Reply] (StateT Env m)) a } deriving (Monad ,Functor ,MonadWriter [Reply] ,MonadState Env ,MonadReader (UTCTime,Conn)) [4]: FWIW, the development section of CREATE-NET, a research centre in Italy. We are hiring Haskellers for application dev… ___ 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
[Haskell-cafe] Custom monad using ST
Hello, I am trying to make a monad that uses ST internally. But even when reducing this to the simplest case I'm still cramped by the 's' phantom type : {-# LANGUAGE Rank2Types #-} newtype MyST a = MyST (forall s. ST s a) -- ^ I cannot use deriving (Monad) through GeneralizedNewtypeDeriving runMyST (MyST m) = runST m -- ^ works thanks to declaration of 's' at rank 2 in the definition of MyST -- It refuses to compile if MyST is declared as such: -- data MyST s a = MyST (ST s a) instance Monad MyST where return = MyST . return -- and this does not compile (MyST m) = f = MyST $ do x - m case f x of (MyST m) - m If you try it, GHC will complain: Simple.hs:13:20: Couldn't match expected type `forall s. ST s a' with actual type `ST s a' Expected type: a - forall s1. ST s1 a Actual type: a - ST s a In the second argument of `(.)', namely `(return :: a - (forall s. ST s a))' In the expression: MyST . (return :: a - (forall s. ST s a)) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom monad using ST
Try `return x = MyST (return x)`. It's (.) that throws it off. - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom monad using ST
Thanks! It works this way. I often forget the dangers of point-free notation... 2011/3/9 Jake McArthur jake.mcart...@gmail.com Try `return x = MyST (return x)`. It's (.) that throws it off. - Jake ___ 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] Custom monad using ST
On Wed, 9 Mar 2011, Yves Parès wrote: Hello, I am trying to make a monad that uses ST internally. But even when reducing this to the simplest case I'm still cramped by the 's' phantom type : {-# LANGUAGE Rank2Types #-} newtype MyST a = MyST (forall s. ST s a) -- ^ I cannot use deriving (Monad) through GeneralizedNewtypeDeriving Would it make sense to make the 's' type explicit? newtype MyST s a = MyST (ST s a) ___ 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 Tue, Mar 8, 2011 at 08:23, Max Bolingbroke batterseapo...@hotmail.com wrote: On 8 March 2011 05:28, Jason Dusek jason.du...@gmail.com wrote: gcc -g -Wall -O2 -fPIC -Wall -o import \ -I/usr/lib/ghc-6.12.1/include/ \ import.c exports.so In my experience, the easiest way to do this is to use gcc to build object files from C source files, and then specify those object files on the ghc command line in order to get GHC to do the linking step. This will deal with linking in the correct RTS and, if you specify appropriate -package flags, dependent packages as well. If you want a C main function then see user guide section 8.2.1.1 at http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html. Following your advice, I was able to get a working main, linking the .o's (no attempt at an SO this time) with GHC. However, what I was hoping to do was build an SO and that could be linked without GHC, for example via Postgres's LANGUAGE C functionality (load SOs and run them) or Ruby's DL/Import (same idea for Ruby). Requiring GHC for linking would really frustrate that goal :) Is there a tutorial I should be following? Well-Typed's blog post on this in the early days of shared object support seemed to be doing what I was doing. -- Jason Dusek Linux User #510144 | http://counter.li.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell Platform web page is out of date
The Haskell Platform web page at http://hackage.haskell.org/platform// seems to need updating. (Incidentally, that double slash at the end doesn't look right). * The next release is promised in Jan 2011. * The Release Timetable schedules the next release for 5 March 2011. I just worry that this is one of the first things someone investigating Haskell sees, and it creates a bad first impression. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Finalizer registered with System.Mem.Weak.addFinalizer is called surprisingly early
Hello, I use addFinalizer from System.Mem.Weak for performing some actions on data just before that is reclaimed by GC. Registered in this way finalizer is called surprisingly early for me, much earlier the data is tend to be collected. I've attached source code of simple two-threaded program. Source code also can be found at [1]. It is pretty simple and should be readable enough. Program is intentioned to pass messages through transactional variable (TVar) for printing by worker thread. Messages consist of formatted to String Int values from 1 to 100. So the output should look like this: 1 2 ... 100 But running the program gives something like that: 1 2 ... 283 finalizing Test: thread blocked indefinitely in an STM transaction As far as I see, finalizer is called too early. If someone could point me out how to do the right thing, that would be helpful. Operaton system: Debian Squeeze Compiler: GHC 6.12.1 Compiling options: none, just ghc --make Test.hs Thanks, balodja [1] http://hpaste.org/44648 -- Simple example of message passing through TVar from base thread -- to worker. Worker thread waits for messages on TVar and prints them out, -- while base thread sends messages with 10ms delay. module Main where import System.Mem.Weak (addFinalizer) import Control.Concurrent (ThreadId, forkIO, threadDelay, killThread) import Control.Concurrent.STM (TVar, newTVarIO, readTVar, writeTVar, atomically, retry) import Control.Monad (when, forever, forM_) -- Data type for holding transaction variable and information about worker thread data Socket = Socket ThreadId (TVar String) -- Open socket means: -- * create TVar for interaction between base and worker threads -- * launch worker thread -- * set finalizer on socket, that kills worker thread when the socket -- is garbage collected open :: IO Socket open = do var - newTVarIO threadId - forkIO (loop var) -- launch worker thread let sock = Socket threadId var addFinalizer sock $ do putStrLn finalizing killThread threadId return sock where loop var = forever $ do x - atomically $ extract var -- wait on TVar, read it putStrLn x -- then print it, then repeat extract var = do x - readTVar var when (x == ) retry -- when no pending message, just wait writeTVar var return x -- Send message. When there is already any message for delivery, -- just wait and retry. send :: Socket - String - IO () send sock@(Socket _ var) msg = do atomically $ do x - readTVar var when (x /= ) retry writeTVar var msg main :: IO () main = do socket - open forM_ [1..100] $ \x - do send socket (show x) threadDelay (10*1000) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Platform web page is out of date
We're about 1 day away from the release. Hold tight!! -- Don (scramble scramble) On Wed, Mar 9, 2011 at 1:21 PM, Paul Johnson p...@cogito.org.uk wrote: The Haskell Platform web page at http://hackage.haskell.org/platform// seems to need updating. (Incidentally, that double slash at the end doesn't look right). * The next release is promised in Jan 2011. * The Release Timetable schedules the next release for 5 March 2011. I just worry that this is one of the first things someone investigating Haskell sees, and it creates a bad first impression. Paul. ___ 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] Finalizer registered with System.Mem.Weak.addFinalizer is called surprisingly early
On Wed, Mar 9, 2011 at 3:54 PM, balodja balo...@zlug.asia wrote: Hello, I use addFinalizer from System.Mem.Weak for performing some actions on data just before that is reclaimed by GC. Registered in this way finalizer is called surprisingly early for me, much earlier the data is tend to be collected. I've attached source code of simple two-threaded program. Source code also can be found at [1]. It is pretty simple and should be readable enough. Does it work if you change: forM_ [1..100] $ \x - do send socket (show x) threadDelay (10*1000) to: forM_ [1..100] $ \x - do send socket (show x) touch socket threadDelay (10*1000) Where touch is found in Control.Monad.Primitive of the package primitive: http://hackage.haskell.org/packages/archive/primitive/0.3.1/doc/html/Control-Monad-Primitive.html#v:touch I'm guessing what happens is that optimizations make the 'Socket' constructor go away, so the finalizer runs as soon as it can. The 'touch' function might force it to stick around. You'll probably want to look at the low-level compiler output to make sure: http://hackage.haskell.org/package/ghc-core Does anyone else have any good tutorials to link to? Antoine Program is intentioned to pass messages through transactional variable (TVar) for printing by worker thread. Messages consist of formatted to String Int values from 1 to 100. So the output should look like this: 1 2 ... 100 But running the program gives something like that: 1 2 ... 283 finalizing Test: thread blocked indefinitely in an STM transaction As far as I see, finalizer is called too early. If someone could point me out how to do the right thing, that would be helpful. Operaton system: Debian Squeeze Compiler: GHC 6.12.1 Compiling options: none, just ghc --make Test.hs Thanks, balodja [1] http://hpaste.org/44648 ___ 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
Both your replies where very helpful. I combined both approaches to get nearer to what I want. class Lit α where lit ∷ Integer → α class Add α where add ∷ α → α → α instance Lit Integer where lit = fromInteger instance Add Integer where add = (+) This time I require TypeSynonymInstances: instance Lit String where lit = show instance Add String where add x y = ( ++ x ++ + ++ y ++ ) Felipe's generalized context type: data AddCtx α = Empty | AddL α (AddCtx α) | AddR α (AddCtx α) Combination of Oleg's tagless transformer and Felipe's CtxInterpB: instance (Add α, Add β) ⇒ Add (AddCtx β → α, β) where add (xa, xb) (ya, yb) = ( \c → add (xa (AddL yb c)) (ya (AddR xb c)) , add xb yb ) The previous instance allows me to construct Strings while having Integers in the context. Silly interpreter, version 2.0 instance Lit (AddCtx Integer → String, Integer) where lit n = ( \c → case c of AddL 3 _ → Foo! _ → lit n , lit n ) Simple term: t1 ∷ (Lit α, Add α) ⇒ α t1 = lit 2 `add` lit 3 Interpret as a String: bar = let (f, x) = t1 ∷ (AddCtx Integer → String, Integer) in f Empty (Foo! + 3) 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. My plan is to define the context as a type class. Obviously I can't perform case analysis on a polymorphic type so I'll have to add that functionality to each context class in some way. Thank you for your helpful replies! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom monad using ST
Well, I want to hide the fact that I'm using ST, so if I can hide the existential type 's' it is better. 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? 2011/3/9 Henning Thielemann lemm...@henning-thielemann.de On Wed, 9 Mar 2011, Yves Parès wrote: Hello, I am trying to make a monad that uses ST internally. But even when reducing this to the simplest case I'm still cramped by the 's' phantom type : {-# LANGUAGE Rank2Types #-} newtype MyST a = MyST (forall s. ST s a) -- ^ I cannot use deriving (Monad) through GeneralizedNewtypeDeriving Would it make sense to make the 's' type explicit? newtype MyST s a = MyST (ST s a) ___ 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.
Hi Jason, Following your advice, I was able to get a working main, linking the .o's (no attempt at an SO this time) with GHC. I haven't tried it, but how about this: 1. Use ghc to link a standard Haskell executable that requires your libraries. Run the link step with -v so you can see the linker flags GHC uses. 2. Use those link flags to link a .so instead. Importantly, this .so will have already been linked against the Haskell RTS, so you will be able to link it into a C program with no further dependencies. Now, there will be at least one additional complication. Before C can call into Haskell functions you will need to arrange for hs_init and hs_add_root to be executed. In order to do this you will probably have to write an additional C file, bootstrap.c. This should contain an initialization procedure that calls hs_init and hs_add_root in an function decorated with the __attribute__((constructor)) GCC extension. Bootstrap.o should then be statically linked in with the .so in order to initialise the Haskell RTS when C dynamically links in that .so. Is there a tutorial I should be following? Well-Typed's blog post on this in the early days of shared object support seemed to be doing what I was doing. Last time I checked Well-Typed's blog posts were one of the best sources of information on this rather arcane topic. There is no easy way to make this work at the moment, AFAIK :-( Cheers, Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: Updates in the monadic regions family
Dear all, I released new versions of some of my packages. Here are the changelogs: http://hackage.haskell.org/package/regions-0.9 http://hackage.haskell.org/package/regions-mtl-0.3.1.5 http://hackage.haskell.org/package/regions-monadstf-0.3.1.5 * Switch from monad-peel to monad-control. * Removed Control.Monad.Trans.Region.Concurrent. The fork functions contained bugs which could not be fixed. I'm working on a way to copy handles from one thread to another but the design has not settled yet. * Removed Data.RegionRef. I always considered this module a bit of a wart. * Added support for local regions. Primarily needed for the alloca functions from the regional-pointers package. More on that below. http://hackage.haskell.org/package/regional-pointers-0.6 * Switch from monad-peel to monad-control. * Major API change: Use the new local regions. This means that instead of: alloca ∷ (Storable α, MonadPeelIO pr) ⇒ (∀ s. RegionalPtr α (RegionT s pr) → RegionT s pr β) → pr β I now have: alloca ∷ (Storable α, MonadControlIO pr) ⇒ (∀ sl. LocalPtr α (LocalRegion sl s) → RegionT (Local s) pr β) → RegionT s pr β This allows my alloca to use the native alloca which is more efficient than doing a manual malloc and free as I did before. The type also allows to open resources in the continuation and use them outside the continuation and visa versa. * Have separate types for the three different pointers: - RegionalPtr: for pointers created using malloc. - LocalPtr: for pointers created using alloca. - NullPtr: for the nullPtr. * Add the type classes Pointer and AllocatedPointer to classify them. http://hackage.haskell.org/package/safer-file-handles-0.10 http://hackage.haskell.org/package/safer-file-handles-bytestring-0.2 http://hackage.haskell.org/package/safer-file-handles-text-0.2 * Switch from monad-peel to monad-control. * Support regional-pointers-0.6 and use its overloaded pointers. * Add separate types for standard handles: StdFileHandle and normal handles: RegionalFileHandle. * Add the type class FileHandle to group them. * Overload the filehandle in operations. http://hackage.haskell.org/package/usb-0.8 * getStrDesc and getStrDescFirstLang now return a Text instead of a String. This is a more efficient and cleaner interface. http://hackage.haskell.org/package/usb-enumerator-0.3 * Switch from monad-peel to monad-control. * Support iteratee-0.8.*. * Support usb-0.9. http://hackage.haskell.org/package/usb-safe-0.12 * Switched from monad-peel to monad-control. * Exported the ReadEndpoint, WriteEndpoint and EnumReadEndpoint type classes so you can refer to them in type signatures. * Support usb-0.8: getStrDesc and getStrDescFirstLang now return a Text instead of a String. * Support regions-0.9. * Support usb-enumerator-0.3. * Support iteratee-0.8.*. Regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom monad using ST
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
[Haskell-cafe] Haskell Weekly News: Issue 172
Welcome to issue 172 of the HWN, a newsletter covering developments in the [1]Haskell community. This release covers the week of February 27 to March 05, 2011. Announcements Jasper Van der Jeugt [2]announced the release of version 3 of Hakyll. He informs us that this is a complete re-write, and not backwards compatible. Horvath Zoltan [3]informed us about the 4th Central European Functional Programming School (CEFP 2011), which is to take place in Eotvos Lorand University, Budapest, Hungary, from June 14-24, 2011. The invited lecturers are the most prominent researchers in the field in Europe, and they will present state-of-the-art functional programming techniques. Janis Voigtlander [4]issued a call for papers for the 20th International Workshop on Functional and (Constraint) Logic Programming (WFLP 2011) to be held in Odense, Denmark, on July 19, 2011. Michael Hanus [5]issued a call for papers for the 13th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming (PPDP 2011) to be held in Odense, Denmark, on July 20-22, 2011. Trystan Spangler [6]released a new version (0.3.0) of hspec, with improvements including fixing a base dependency problem, and better reporting of failed examples. Magnus Therming [7]released new versions of dataenc (0.14), and omnicodec (0.5). It contains a large change to the API. The old, rather simplistic, lazy API has been removed. It has been replaced by an API based on incremental encoding/decoding. This should make the library easier to use together with left-fold enumerators... Rogan Creswick [8]announced that cabal-dev 0.7.4.0 has been uploaded to hackage. We strongly suggest that everyone upgrade to this release, since this release specifically addresses changes in Cabal-1.10 and newer, which the latest cabal-install new uses. Frederick Ross [9]announced a minor upgrade to haskell-pgm (0.1.2), with a minor upgrade to the library to make it work with GHC 7. Uwe Schmidt [10]announced an update to hxt to version 9.1. Eric Kow [11]announced that the date and venue for the sixth Darcs Hacking sprint has been confirmed for Paris, April 1-3, 2011. Ian Lynagh and the GHC Team [12]announced a new patchlevel release of GHC. This release contains a number of bugfixes relative to 7.0.1, so we recommend upgrading. Denis Bueno [13]announced new releases of funsat (0.6.2) and bitset (1.1). Michal Konecny [14]announced version 0.3.2 of hmpfr, bindings to the MPFR arbitrary precision floating point arithmetic library. The changes in this version are quite small but significant. Jonathan Daugherty [15]announced version 1.0 of the vty-ui terminal user interface library. The vty-ui library is a complete interactive user interface development toolkit for terminal applications. Jason Dusek [16]announced his now bash-0.0.0, which has types and functions for generation of Bash scripts, with safe escaping and composition of large subsets of Bash statements and expressions. Quotes of the Week * lpsmith: I didn't take the time to figure out what should be done in finite cases. * companion_cube edwardk, you mean it's 2 phD/nick in average ? :) edwardk clearly this is why SPJ stays away, he doesn't want to dilute that metric. * edwardk: Haskell 98 is a laudable goal. * douglas-adams: I love deadlines, I especially like the swooshing sound they make as they fly past * kmc: the way to convert imperative code to functional is to think about what your code actually means, and then throw out most of the irrelevant details that imperative programming has forced on you * MonadsSuck: man, I hate it when an adjoint pair of functors get together and compose. So damn annoying * bwright: I don't get it everyone keeps telling me java is a safe language but it melted the plastic on my eeepc900 * danka: you could be a monadic vampire. I hear they bleed semicolons. Top Reddit Stories * ANNOUNCE: GHC version 7.0.2: From (haskell.org), scored 46 with comments. Read on [17]reddit or the [18]original post. * Greenfield Haskell: From (self.haskell), scored 36 with 188 comments. Read on [19]reddit or the [20]original post. * Patches for monad comprehensions are in and will be in the upcoming GHC 7.2 release: From (hackage.haskell.org), scored 34 with 15 comments. Read on [21]reddit or the [22]original post. * GHC 7.0.2 released!: From (haskell.org), scored 32 with 10 comments. Read on [23]reddit or the [24]original post. * Haskell on Android: From (self.haskell), scored 31 with 22 comments. Read on [25]reddit or the [26]original post. * Do you think Haskell will ever catch on?: From (self.haskell), scored 26 with 63 comments. Read
Re: [Haskell-cafe] [Haskell] Linker flags for foreign export.
I've gleaned a little bit of useful info from looking at what GHC spits out with -v; I found that ordering the libraries in the way they do it makes one of my undefined symbols (`hs_free_stable_ptr') go away. However, my library ends up with a couple undefined __stginit_* symbols which prevent it from loading. I thought this might be a symptom of building Foo.o from Foo.hs with -dynamic; and indeed, building it without the -dynamic flag gives me an SO with many, many __stginit_* functions defined in it; but that SO causes the loader to segfault (both Ruby's DL/Import and my little test program). 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: https://github.com/solidsnack/bash/tree/0e93b6aed7971886c12b95646e5baadc40fe62bc/hs/well-typed The three different permutations of SOs -- fully dynamic, fully static and hybrid -- each fail to load differently: :; ./loadfoo ./libfoo.dynamic-dynamic.so trying to load ./libfoo.dynamic-dynamic.so .so load error: /usr/lib/ghc-6.12.1/base-4.2.0.0/libHSbase-4.2.0.0-ghc6.12.1.so: undefined symbol: forkOS_createThread :; ./loadfoo ./libfoo.static-static.so trying to load ./libfoo.static-static.so Segmentation fault :; ./loadfoo ./libfoo.dynamic-static.so trying to load ./libfoo.dynamic-static.so .so load error: ./libfoo.dynamic-static.so: undefined symbol: __stginit_base_Prelude_dyn The little tester program, `loadfoo', is drawn from the blog post's example; Ruby's DL/Import fails the same way in each case. It would be pretty nice to demo an easy way to load and work with Haskell functions from Ye Olde Favorite Language. Seems like SOs for the masses will have to wait a little bit, though. -- Jason Dusek Linux User #510144 | http://counter.li.org/ ___ 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?
Confirmed for me on IPv6 as well. -- Simon Heath http://alopex.li/ Science, games, computers, life. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] possible bug for ghc 7 + xcode 4 on snow leopard?
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
Re: [Haskell-cafe] possible bug for ghc 7 + xcode 4 on snow leopard?
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
Re: [Haskell-cafe] Haskell mail server fail?
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) -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Finalizer registered with System.Mem.Weak.addFinalizer is called surprisingly early
Thank you for your answer. Does it work if you change: forM_ [1..100] $ \x - do send socket (show x) threadDelay (10*1000) to: forM_ [1..100] $ \x - do send socket (show x) touch socket threadDelay (10*1000) Yes, that works. I'm guessing what happens is that optimizations make the 'Socket' constructor go away, so the finalizer runs as soon as it can. The 'touch' function might force it to stick around. You'll probably want to look at the low-level compiler output to make sure: http://hackage.haskell.org/package/ghc-core As far as I see you are definitely right. Due to good inlining Socket constructor is not needed in main forM-cycle. After some meditation on core output I added NOINLINE pragma to function send and the problem vanished. Is NOINLINE pragma a good workaround in such situation? Thanks, balodja ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Automated tests with cabal
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? Thanks Klaus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell mail server fail?
2011/3/10 wren ng thornton w...@freegeek.org 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? I don't have the status, but I am still receiving emails from cafe and libraries. David. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe