Re: [Haskell-cafe] Simple way to do something like ArrowChoice.right on a Conduit? (version 1.0.0)
On Fri, Mar 1, 2013 at 4:18 AM, Joey Adams joeyadams3.14...@gmail.comwrote: Can I transform a conduit so some values are passed through unchanged, but others go through the conduit? For example: right :: Conduit i m o - Conduit (Either x i) m (Either x o) This is named after the Control.Arrow combinator of the same name: right :: ArrowChoice a = a b c - a (Either d b) (Either d c) Here's my use case (simplified): I want to compress data with zlib-conduit, which provides: compress :: Conduit (Flush ByteString) m (Flush ByteString) The Flushhttp://hackage.haskell.org/packages/archive/conduit/latest/doc/html/Data-Conduit.html#t:Flushwrapper lets me flush the compressor so it will yield cached data right away (though hurting compression a little). But before compressing the data, I want to encode it, using this conduit: encode :: Conduit Entry m ByteString I want to combine these, so that if I send a 'Flush', it bypasses 'encode' and feeds to 'compress': compressEncode :: Conduit (Flush Entry) m (Flush ByteString) Thus, I need a variant of 'encode' that passes 'Flush' along: encode' :: Conduit (Flush Entry) m (Flush ByteString) In my actual program, I don't use Flush, so providing a Conduit combinator just for Flush would not help me. Is something like 'right' possible to implement with Conduit's public API? Here's an implementation using Data.Conduit.Internal (untested): import Control.Monad (liftM) import Data.Conduit.Internal (Pipe(..), ConduitM(..), Conduit) right :: Monad m = Conduit i m o - Conduit (Either x i) m (Either x o) right = ConduitM . rightPipe . unConduitM rightPipe :: Monad m = Pipe i i o () m () - Pipe (Either x i) (Either x i) (Either x o) () m () rightPipe p0 = case p0 of HaveOutput p c o - HaveOutput (rightPipe p) c (Right o) NeedInput p c - NeedInput p' (rightPipe . c) where p' (Left x) = HaveOutput (rightPipe p0) (return ()) (Left x) p' (Right i) = rightPipe $ p i Done r- Done r PipeM mp - PipeM $ liftM rightPipe mp Leftover p i - Leftover (rightPipe p) (Right i) I'm fairly certain this cannot be implemented using only the public API. Your implementation looks solid to me. I'm wondering if we could have a Data.Conduit.Arrow module, which provides a newtype variant of Conduit that implements Arrow, ArrowChoice, etc.: import qualified Data.Conduit as C newtype Conduit m i o = Conduit (C.Conduit i m o) -- May need Monad constraints for these instance Category (Conduit m) instance Arrow (Conduit m) instance ArrowChoice (Conduit m) As I think you point out in your next email, Conduit can't really be an instance of Arrow. IIRC, there was quite a bit of talk about that when pipes came out, but some of the features of a Pipe (such as allowing input and output to occur at different speeds) means that it can't be achieved. Nonetheless, I think adding some helping combinators based around Arrows for Conduit makes sense. Does 'Conduit' follow Category, Monad, MonadTrans laws* these days? I'm not talking about Pipe in general, just the special case of it represented by the 'Conduit' type alias: Conduit i m o = ConduitM i o m () = Pipe i i o () m () Or are there some thorny issues (e.g. leftovers) that make following these laws impossible in some cases? It's easy to prove that a Conduit with leftovers does not follow the Category laws: id = awaitForever yield (.) = (=$=) id . leftover x /= leftover x That was the motivation for adding the leftover type parameter to the Pipe datatype: if you want to get closer to a Category instance (whatever closer would mean here), you need to make sure that the leftover parameter is set to Void. However, even in such a case, there's at least one deviation from strict Category behavior. The order in which finalizers are run does not fully respect the associative laws[1]. In this case, the deviation is intentional: conduit is more concerned with ensuring strict resource usage than associativity. I touched on this point briefly in a recent conduit 1.0 blog post. In my opinion, this is evidence that Category is not the right abstraction to be used for streaming data, since it doesn't give us the ability to guarantee prompt finalization. [1] https://github.com/snoyberg/conduit/pull/57 Thanks for the input, -Joey * Assume functions that use Data.Conduit.Internal do so correctly. ___ 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 syntax/indentation for vim
Hi Have you seen vim2hs? https://github.com/dag/vim2hs On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch travi...@cs.wisc.eduwrote: Cafe, I've recently been playing with vim and wasn't quite satisfied with the existing syntax highlighting and indentation, so I thought I'd try my hand at a new Haskell mode: https://github.com/travitch/hasksyn It is minimal in that it doesn't provide support for running external commands over code or anything fancy. It just does syntax highlighting and reasonably-smart indentation. There is no support for literate Haskell since supporting both with one mode is very tricky. It might be useful to some people. Comments, bug reports, and suggestions welcome. ___ 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 syntax/indentation for vim
I see now in your README that you have seen vim2hs. I'd love to hear what you disliked about it, especially given my plan to rewrite the whole thing [1]! :) [1] https://github.com/dag/vim2hs/issues/45 On Sun, Mar 3, 2013 at 3:38 PM, dag.odenh...@gmail.com dag.odenh...@gmail.com wrote: Hi Have you seen vim2hs? https://github.com/dag/vim2hs On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch travi...@cs.wisc.eduwrote: Cafe, I've recently been playing with vim and wasn't quite satisfied with the existing syntax highlighting and indentation, so I thought I'd try my hand at a new Haskell mode: https://github.com/travitch/hasksyn It is minimal in that it doesn't provide support for running external commands over code or anything fancy. It just does syntax highlighting and reasonably-smart indentation. There is no support for literate Haskell since supporting both with one mode is very tricky. It might be useful to some people. Comments, bug reports, and suggestions welcome. ___ 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] building darcs failed (Unable to link against the iconv library)
Trying to install darcs with cabal-install: Linking /tmp/darcs-2.8.4-12051/darcs-2.8.4/dist/setup/setup ... Configuring darcs-2.8.4... checking whether to use -liconv... setup: Unable to link against the iconv library. Failed to install darcs-2.8.4 cabal: Error: some packages failed to install: What is actually going on here? Iconv libraries already installed with libc6 package. Running ubuntu, cabal-install-1.16.0.2. -- Best regards, dmitry malikov ! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Future of MonadCatchIO
Hi all, The function 'block' and 'unblock' (from Control.Exception) have been deprecated for some time, and are apparantly now being removed (in favour of 'mask'). Generalisations of these functions are (part of) the interface of MonadCatchIO-transformers (the 'MonadCatchIO' class has methods 'block' and 'unblock'). So, the interface would have to change to keep up with base. I'm inclined to deprecate MonadCatchIO-transformers itself, in favour of monad-control. I suspect that most clients do not use 'block' or 'unblock' directly, but use only derived functions, like 'bracket'. (I have partly confirmed this, by inspecting some reverse dependencies on hackage.) This allow an easy transition to monad-control: in many cases, only imports will need to be changed. In the minority of cases where 'block' and 'unblock' are used and/or instances of MonadCatchIO are defined, code will need to be updated. There is a difference in functionality between MonadCatchIO and monad-control. In the former, 'bracket' will not perform the final action if the main action is an ErrorT that throws an error (in contrast with exceptions in the underlying IO monad). In monad-control, 'bracket' will perform the final action in this case. (See this discussion for background: http://www.haskell.org/pipermail/haskell-cafe/2010-October/084890.html.) Probably, in most use cases the behaviour of monad-control is preferred. This seems to be the case also for snap, which uses MonadCatchIO-transformers, but defines its own variant of 'bracket' to get the right behaviour. Would anyone have a problem with a deprecation of MonadCatchIO-transformers, and a failure to update it to work with a base without 'block' and 'unblock'? Regards, Arie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] simple parsec question
Hi, I am trying to parse a semi structured text with parsec that basically should identify sections. Each section starts with a headline and has an unstructured content - that's all. For instance, consider the following example text (inside the dashed lines): --- top 1: some text ... bla top 2: more text ... bla bla --- This should be parsed into a structure like this: [Section (Top 1) (Content some text ... bla), Section (Top 1) (Content more text ... bla)] Say, I have a parser headline, but the content after a headline could be anything that is different from what headline parses. How could the section parser making use of headline look like? My idea would be to use the manyTill combinator, but I dont find an easy solution. Many thanks for any hint Immanuel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal: TypeDirectedNameResolution
simonpj wrote: What do I envy about object-oriented languages? Not state, not subtyping, not inheritance. But I do envy the power of type-based name resolution. Here's what I mean: Programers can explore a library, with the help of an IDE, by typing x., at which point a list of x's methods pops up. That feature is not really from OOP, as he also wrote. It is possible just because in Java or C++ you write the object first and then the method, connected with a dot. So, we could say that most of the OOP languages uses RPN (Reverse Polish Notation), but only for one argument: the object itself. If Haskell would have been designed for RPN, it would be natural to have the same IDE power as the OOP languajes, in a more natural way. For example, as you write an integer the IDE could offer you the unary functions that can be applied to an integer, but if you enter a string after it, the IDE would offer you the functions of two arguments, one of them of type string and the other of type integer. That would be much more powerfull indeed than the OOP case. It could be used not only on an IDE, but also on the interpreter, and not only with declared names, but also with implicit types like numbers, text strings, tuples, enum elements, ... It would be easier work for the compiler as well. So, I think that it was not a good design decision not to use RPN as the basic notation for Haskell, but it is late for changing it :( . ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
Arie Peterson ar...@xs4all.nl wrote: Would anyone have a problem with a deprecation of MonadCatchIO-transformers, and a failure to update it to work with a base without 'block' and 'unblock'? Yes. This is a simplified variant of a monad I use: newtype Continue f m a = Continue (m (Maybe a, f (Continue f a))) It's related to Cofree and has a valid and very straightforward MonadCatchIO instance. However, it's probably impossible to write a valid MonadTransControl/MonadBaseControl instance for it. So I kindly ask you not to deprecate MonadCatchIO. The reason I'm hesitant about moving to monad-control is that it's hard to understand and also very difficult to define for CPS monads. It is commonly believed to be impossible. Also I've seen at least one article about the incorrectness of monad-control. That's one further reason I like to avoid it. Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] simple parsec question
Immanuel, Since a heading always starts with a new line (and ends with a colon followed by a carriage return or just a colon?), I think it might be useful to first separate the input into lines and then classify them depending on whether it's a heading or not and reassemble them into the value you need. You don't even need parsec for that. However, if you really want to use parsec, you can write something like (warning, not tested): many $ liftM2 Section headline content where headline = anyChar `manyTill` (char ':' spaces newline) content = anyChar `manyTill` (try $ newline headline) /Andrey On 3/3/2013 10:44 AM, Immanuel Normann wrote: I am trying to parse a semi structured text with parsec that basically should identify sections. Each section starts with a headline and has an unstructured content - that's all. For instance, consider the following example text (inside the dashed lines): --- top 1: some text ... bla top 2: more text ... bla bla --- This should be parsed into a structure like this: [Section (Top 1) (Content some text ... bla), Section (Top 1) (Content more text ... bla)] Say, I have a parser headline, but the content after a headline could be anything that is different from what headline parses. How could the section parser making use of headline look like? My idea would be to use the manyTill combinator, but I dont find an easy solution. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Proposal: TypeDirectedNameResolution
Enrique enriqu...@gmail.com wrote: So, I think that it was not a good design decision not to use RPN as the basic notation for Haskell, but it is late for changing it :( . I don't think you want that anyway. First of all, meet van Laarhoven lenses [1]: x ^. field . subfield This has the order you know from OOP, so the basic syntactic support for quick method auto-suggestion is there. You don't even need Control.Category, because the (.) is actually the regular function composition operator. So where to go from here? One advantage of Haskell is that there is no such thing as a method. It's all functions and values, and you can actually establish a measure for how exactly a type captures another. Now just auto-suggest /all/ functions in scope sorted by how exactly their type matches. You can do that without lenses, if you have a smart editor: stdout ` Now it might display something like this: stdout `[hPutStrLn] [hSetBuffering] [hClose ] [... ] [const] [id ] Finally when you select one of the functions it rewrites it to: hPutStrLn stdout Of course in a real editor you would also show the type signature and probably also the module from where it was imported. I consider the record problem solved in Haskell. Greets, Ertugrul [1]: http://hackage.haskell.org/package/lens -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
Ertugrul Söylemez e...@ertes.de wrote: newtype Continue f m a = Continue (m (Maybe a, f (Continue f a))) Typo: newtype Continue f m a = Continue (m (Maybe a, f (Continue f m a))) Sorry. Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad. signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
On Sun, Mar 3, 2013 at 6:07 PM, Ertugrul Söylemez e...@ertes.de wrote: Arie Peterson ar...@xs4all.nl wrote: Would anyone have a problem with a deprecation of MonadCatchIO-transformers, and a failure to update it to work with a base without 'block' and 'unblock'? Yes. This is a simplified variant of a monad I use: newtype Continue f m a = Continue (m (Maybe a, f (Continue f a))) It's related to Cofree and has a valid and very straightforward MonadCatchIO instance. However, it's probably impossible to write a valid MonadTransControl/MonadBaseControl instance for it. Perhaps there's a good reason why it's impossible to make such an instance. Are you sure that your MonadCatchIO instance is well founded? What happens if you use finally? Are you guaranteed that your cleanup function is called once, and precisely once? These are the problems I ran into with MonadCatchIO three years ago, almost precisely. The main monad for Yesod was built around ContT, and I ended up with double-free bugs. It's true that I had to move away from ContT in order to get the desired semantics, but that has nothing to do with MonadCatchIO vs monad-control. The former just made it seem like I had working code when in fact I had a lurking bug. So I kindly ask you not to deprecate MonadCatchIO. The reason I'm hesitant about moving to monad-control is that it's hard to understand and also very difficult to define for CPS monads. It is commonly believed to be impossible. Also I've seen at least one article about the incorrectness of monad-control. That's one further reason I like to avoid it. I've seen the criticisms of monad-control (or at least I believe I have). What I've seen has been dubious at best. I'll fully agree that the implementation is hard to follow, but it's designed for efficiency. The underlying concept is simple: capture the current state and pipe it through the underlying monad. If you needed to lift a control operation for the ReaderT or StateT monads, you would likely end up with an almost exact replica of what monad-control does for you. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
On Sunday 03 March 2013 17:07:18 Ertugrul Söylemez wrote: Would anyone have a problem with a deprecation of MonadCatchIO-transformers, and a failure to update it to work with a base without 'block' and 'unblock'? Yes. This is a simplified variant of a monad I use: newtype Continue f m a = Continue (m (Maybe a, f (Continue f a))) It's related to Cofree and has a valid and very straightforward MonadCatchIO instance. However, it's probably impossible to write a valid MonadTransControl/MonadBaseControl instance for it. Is it possibly to write the equivalent of Control.Exception.mask for it? That would be the first candidate for replacing block and unblock in the MonadCatchIO class. Regards, Arie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What pattern is this (Something.T - IO a) in Sound.ALSA.Sequencer
Hello all, this was previously posted on Haskell Beginners, but only partially answered. In Sound.ALSA.Sequencer, there are a number of functions which together set up a midi environement (client, port, queue). They all have a type, where the last argument has a type like: (something.T - IO a) i.e. *Main :t SndSeq.withDefault SndSeq.withDefault :: SndSeq.OpenMode mode = SndSeq.BlockMode - (SndSeq.T mode - IO a) - IO a *Main :t Port.withSimple Port.withSimple :: SndSeq.T mode - String - Port.Cap - Port.Type - (Port.T - IO a) - IO a *Main :t Queue.with Queue.with :: SndSeq.T mode - (Queue.T - IO a) - IO a There is example code, where a full setup is created by a number of nested do blocks. The repeating pattern there is: something1 $ \x - do something2 $ \y - do something3 $ \z - do What is this all about? I particularly would like to understand, when this parttern is needed and what determines the the number of nested do blocks. -- Martin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] building darcs failed (Unable to link against the iconv library)
On Sun, Mar 3, 2013 at 10:21 AM, Dmitry Malikov malikov@gmail.comwrote: checking whether to use -liconv... setup: Unable to link against the iconv library. Failed to install darcs-2.8.4 cabal: Error: some packages failed to install: What is actually going on here? Iconv libraries already installed with libc6 package. Running ubuntu, cabal-install-1.16.0.2. Linux distinguishes between runtime and linkable libraries; you probably need to install the libc6-dev package to get the latter. (This is not a Haskell-specific issue; configure is using a C program to test the link.) -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] building darcs failed (Unable to link against the iconv library)
On 03/03/2013 10:56 PM, Brandon Allbery wrote: On Sun, Mar 3, 2013 at 10:21 AM, Dmitry Malikov malikov@gmail.com mailto:malikov@gmail.com wrote: checking whether to use -liconv... setup: Unable to link against the iconv library. Failed to install darcs-2.8.4 cabal: Error: some packages failed to install: What is actually going on here? Iconv libraries already installed with libc6 package. Running ubuntu, cabal-install-1.16.0.2. Linux distinguishes between runtime and linkable libraries; you probably need to install the libc6-dev package to get the latter. (This is not a Haskell-specific issue; configure is using a C program to test the link.) -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com mailto:allber...@gmail.com ballb...@sinenomine.net mailto:ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net But libc6-dev is already the newest version. -- Best regards, dmitry malikov ! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] building darcs failed (Unable to link against the iconv library)
On Sun, Mar 3, 2013 at 1:59 PM, Dmitry Malikov malikov@gmail.comwrote: On 03/03/2013 10:56 PM, Brandon Allbery wrote: On Sun, Mar 3, 2013 at 10:21 AM, Dmitry Malikov malikov@gmail.comwrote: checking whether to use -liconv... setup: Unable to link against the iconv library. What is actually going on here? Iconv libraries already installed with libc6 package. Linux distinguishes between runtime and linkable libraries; you probably need to install the libc6-dev package to get the latter. (This is not a Haskell-specific issue; configure is using a C But libc6-dev is already the newest version. Then you'll have to check config.log (this probably means doing the build manually with cabal unpack darcs and then running cabal install without a package name from the directory with the darcs.cabal file) to see what's going wrong. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What pattern is this (Something.T - IO a) in Sound.ALSA.Sequencer
On Sun, Mar 3, 2013 at 10:28 AM, Martin Drautzburg martin.drautzb...@web.de wrote: Hello all, this was previously posted on Haskell Beginners, but only partially answered. In Sound.ALSA.Sequencer, there are a number of functions which together set up a midi environement (client, port, queue). They all have a type, where the last argument has a type like: (something.T - IO a) These things are in the Kleisli category for IO. In short, an argument with this type is a function which makes an IO action. The function which takes one of these as an action knows how to get a something.T to apply to the function, either because it is an argument to the bigger function, or because the library author knows the monad has an action with the type IO (something.T). This is safer than passing around unconstrained IO actions. For example, consider: outer :: String - (Int - IO ()) - IO () versus outer :: String - IO () - IO () The second type requires that the library user can construct an appropriate IO () action, and the intended dependence on the Int is not statically verified. On the other hand, the first type requires that you pass in an IO () action constructor that explicitly depends on an Int. The only way you can drop the dependence on the Int is if you explicitly ignore it (and you can turn on warnings to catch that kind of thing) i.e. *Main :t SndSeq.withDefault SndSeq.withDefault :: SndSeq.OpenMode mode = SndSeq.BlockMode - (SndSeq.T mode - IO a) - IO a *Main :t Port.withSimple Port.withSimple :: SndSeq.T mode - String - Port.Cap - Port.Type - (Port.T - IO a) - IO a *Main :t Queue.with Queue.with :: SndSeq.T mode - (Queue.T - IO a) - IO a There is example code, where a full setup is created by a number of nested do blocks. The repeating pattern there is: something1 $ \x - do something2 $ \y - do something3 $ \z - do What is this all about? I particularly would like to understand, when this parttern is needed and what determines the the number of nested do blocks. It can be refactored, so it is never needed. On the other hand, it does have nice properties. The x,y, z variables are all in scope when you're in something3's do-block argument. The determining factor in the nesting depth is how many actions which take elements of a Kliesli category for the monad will be sequenced, since each one requires its own lambda-do-block. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What pattern is this (Something.T - IO a) in Sound.ALSA.Sequencer
Hi Martin, These are called continuations or callbacks. In this case, the term callback seems to fit better, since the result of continuation is an IO action. The common use case for callbacks is when you want to release some resources after the IO action completes. Let's look at the definition of withSimple: withSimple :: Seq.T mode - String - Port.Cap - Port.Type - (Port.T - IO a) - IO a withSimple ss s c t = bracket (createSimple ss s c t) (deleteSimple ss) It uses the 'bracket' function (from Control.Exception) to acquire resource, run the given IO action with that resource and release the resource afterwards. An important property of bracket is that it is exception-safe: resources will be released even when the supplied action throws an exception. But ignoring exceptions, withSimple is equivalent to withSimple ss s c t callback = do port - createSimple ss s c t callback port deleteSimple ss port The non-callback version of withSimple is createSimple, which returns the Port itself. But it doesn't release the Port afterwards, because it has no way to know when you've finished working with it. Callbacks can often be found in imperative programming. Almost all GUI libraries and some I/O frameworks (notably, node.js) are based on callbacks. Admittedly, programming with callbacks is not very pleasant. So we have an excellent alternative — the continuation monad transformer! This nested code something1 $ \x - do something2 $ \y - do something3 $ \z - do can be equivalently rewritten as this linear code import Control.Monad.Cont flip runContT return $ do x - ContT something1 y - ContT something2 z - ContT something3 lift $ do ... Notice that we completely change the style of interaction with the library without changing the library itself at all! For a complete example you can look at the ValueGetter monad in the test-framework-golden package. Roman * Martin Drautzburg martin.drautzb...@web.de [2013-03-03 19:28:39+0100] Hello all, this was previously posted on Haskell Beginners, but only partially answered. In Sound.ALSA.Sequencer, there are a number of functions which together set up a midi environement (client, port, queue). They all have a type, where the last argument has a type like: (something.T - IO a) i.e. *Main :t SndSeq.withDefault SndSeq.withDefault :: SndSeq.OpenMode mode = SndSeq.BlockMode - (SndSeq.T mode - IO a) - IO a *Main :t Port.withSimple Port.withSimple :: SndSeq.T mode - String - Port.Cap - Port.Type - (Port.T - IO a) - IO a *Main :t Queue.with Queue.with :: SndSeq.T mode - (Queue.T - IO a) - IO a There is example code, where a full setup is created by a number of nested do blocks. The repeating pattern there is: something1 $ \x - do something2 $ \y - do something3 $ \z - do What is this all about? I particularly would like to understand, when this parttern is needed and what determines the the number of nested do blocks. -- Martin ___ 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] Trouble installing and using Chart/cairo on windows 7
Hello, I am trying to install timeplot and splot on a windows 7 host, using Haskell platform 2012.2.0.0, and I have troubles installing HSChart. First difficulties were installing cairo, which requires Gtk+ libraries and headers. I installed those using a Gtk+-bundle, first in c:\Program Files\. I had to move to d:\soft (eg. a directory without spaces) to be able to install cairo. Then I tried to install Chart and at first failed with a cryptic 'Exit Failure 1' error from cabal. I succeeded when I redirected cabal output to a file, eg: cabal install out 21 whereas a plain 'cabal install' failed. Then I managed to install splot and timeplot. I then tried to use Chart to draw a simple chart, following http://hackage.haskell.org/packages/archive/Chart/0.16/doc/html/Graphics-Rendering-Chart-Simple.htmland it hang forever with a CPU at 100%. Suggestions are more than welcomed. Regards, Arnaud ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7
On Sun, Mar 03, 2013 at 09:22:15PM +0100, Arnaud Bailly wrote: Hello, I am trying to install timeplot and splot on a windows 7 host, using Haskell platform 2012.2.0.0, and I have troubles installing HSChart. First difficulties were installing cairo, which requires Gtk+ libraries and headers. I installed those using a Gtk+-bundle, first in c:\Program Files\. I had to move to d:\soft (eg. a directory without spaces) to be able to install cairo. Then I tried to install Chart and at first failed with a cryptic 'Exit Failure 1' error from cabal. I succeeded when I redirected cabal output to a file, eg: cabal install out 21 whereas a plain 'cabal install' failed. Then I managed to install splot and timeplot. I then tried to use Chart to draw a simple chart, following http://hackage.haskell.org/packages/archive/Chart/0.16/doc/html/Graphics-Rendering-Chart-Simple.htmland it hang forever with a CPU at 100%. No idea if it's related, but hanging forever with the CPU at 100% reminds me of this: http://code.google.com/p/diagrams/issues/detail?id=71 Unfortunately, GTK + cairo are notoriously difficult to install on OSX and Windows. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] simple parsec question
Andrey, Thanks for your attempt, but it doesn't seem to work. The easy part is the headline, but the content makes trouble. Let me write the code a bit more explicit, so you can copy and paste it: -- {-# LANGUAGE FlexibleContexts #-} module Main where import Text.Parsec data Top = Top String deriving (Show) data Content = Content String deriving (Show) data Section = Section Top Content deriving (Show) headline :: Stream s m Char = ParsecT s u m Top headline = manyTill anyChar (char ':' newline) = return . Top content :: Stream s m Char = ParsecT s u m Content content = manyTill anyChar (try headline) = return . Content section :: Stream s m Char = ParsecT s u m Section section = do {h - headline; c - content; return (Section h c)} -- Assume the following example text is stored in /tmp/test.txt: --- top 1: some text ... bla top 2: more text ... bla bla --- Now I run the section parser in ghci against the above mentioned example text stored in /tmp/test.txt: *Main parseFromFile section /tmp/test.txt Right (Section (Top top 1) (Content )) I don't understand the behaviour of the content parser here. Why does it return ? Or perhaps more generally, I don't understand the manyTill combinator (though I read the docs). Side remark: of cause for this little task it is probably to much effort to use parsec. However, my content in fact has an internal structure which I would like to parse further, but I deliberately abstracted from these internals as they don't effect my above stated problem. Immanuel 2013/3/3 Andrey Chudnov achud...@gmail.com Immanuel, Since a heading always starts with a new line (and ends with a colon followed by a carriage return or just a colon?), I think it might be useful to first separate the input into lines and then classify them depending on whether it's a heading or not and reassemble them into the value you need. You don't even need parsec for that. However, if you really want to use parsec, you can write something like (warning, not tested): many $ liftM2 Section headline content where headline = anyChar `manyTill` (char ':' spaces newline) content = anyChar `manyTill` (try $ newline headline) /Andrey On 3/3/2013 10:44 AM, Immanuel Normann wrote: I am trying to parse a semi structured text with parsec that basically should identify sections. Each section starts with a headline and has an unstructured content - that's all. For instance, consider the following example text (inside the dashed lines): --- top 1: some text ... bla top 2: more text ... bla bla --- This should be parsed into a structure like this: [Section (Top 1) (Content some text ... bla), Section (Top 1) (Content more text ... bla)] Say, I have a parser headline, but the content after a headline could be anything that is different from what headline parses. How could the section parser making use of headline look like? My idea would be to use the manyTill combinator, but I dont find an easy solution. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RFC: rewrite-with-location proposal
Additionally, Another way to include line number information and to improve readability of the degugging code is to add verify as an assert with flipped parameters so we can write: let x= head xs `verify` (not $ null xs) So the assertions appear on the right , separated from the rest of the code. instead of let x= assert (not $ null xs) xs 2013/2/26 Gershom Bazerman gersh...@gmail.com On 2/25/13 9:42 AM, Simon Peyton-Jones wrote: I’m afraid the rewrite-rule idea won’t work. RULES are applied during optimisation, when tons of inlining has happened and the program has been shaken around a lot. No reliable source location information is available there. ** ** See http://hackage.haskell.org/trac/ghc/wiki/ExplicitCallStack; and please edit it. ** ** One idea I had, which that page does not yet describe, is to have an implicit parameter, something like ?loc::Location, with errLoc :: ?loc:Location = String - a errLoc s = error (“At “ ++ ?loc ++ “\n” ++ s) ** ** This behave exactly like an ordinary implicit parameter, EXCEPT that if there is no binding for ?loc::Location, then the current location is used. Thus I like the general approach of this proposal quite a bit. I'd very much like Location to be not just a string, but a record type. Ideally we could recover not just module name, line and character, but also the name of the function that takes the location. This would eliminate an entire swath of use-cases for Template Haskell. For example, I've worked out a template-haskell-free version of the Cloud Haskell closure API, which hopefully is getting merged in at some point. The major drawback it has is that the user is required to provide a globally-unique identifier for each closure, ideally stable across compilations. The current TH code solves this by grabbing the function and module name. If we could get direct access to these things without requiring template haskell, that would be quite nice. Other types of RPC libraries I've worked on could similarly benefit from this. Cheers, Gershom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Alberto. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7
On 04/03/13 07:22, Arnaud Bailly wrote: Then I managed to install splot and timeplot. I then tried to use Chart to draw a simple chart, following http://hackage.haskell.org/packages/archive/Chart/0.16/doc/html/Graphics-Rendering-Chart-Simple.html and it hang forever with a CPU at 100%. As the author of the Chart library, I'm sorry to say I don't know. Chart is developed under linux, and I do occasional testing under osx, but I don't use windows at all. Chart is a pure haskell library sitting over cairo, so it is most likely a cairo problem rather than a chart one, but I realise this doesn't help you. Do the examples that come with the haskell binding to cairo work for you? Windows and gtk continues to be problematic for many users. I'd love to see an alternative backend for the chart library, but I would need a graphics API that installs easily under windows, osx and linux, and provides good access to fonts and font metrics. Any suggestions? Tim ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7
On Mon, Mar 04, 2013 at 11:26:23AM +1100, Tim Docker wrote: On 04/03/13 07:22, Arnaud Bailly wrote: Then I managed to install splot and timeplot. I then tried to use Chart to draw a simple chart, following http://hackage.haskell.org/packages/archive/Chart/0.16/doc/html/Graphics-Rendering-Chart-Simple.html and it hang forever with a CPU at 100%. As the author of the Chart library, I'm sorry to say I don't know. Chart is developed under linux, and I do occasional testing under osx, but I don't use windows at all. Chart is a pure haskell library sitting over cairo, so it is most likely a cairo problem rather than a chart one, but I realise this doesn't help you. Do the examples that come with the haskell binding to cairo work for you? Windows and gtk continues to be problematic for many users. I'd love to see an alternative backend for the chart library, but I would need a graphics API that installs easily under windows, osx and linux, and provides good access to fonts and font metrics. Any suggestions? Good access to fonts and font metrics is the kicker. Otherwise I'd say to switch to using diagrams as a backend, hence getting a whole bunch of actual backends for free. I would love to see development of some good Haskell font packages -- maybe it would even make a good GSoC project? Unfortunately I don't know enough about it to even know what would be involved, or how much work it would be. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7
On Sun, 3 Mar 2013 19:58:37 -0500 Brent Yorgey byor...@seas.upenn.edu wrote: Good access to fonts and font metrics is the kicker. Otherwise I'd say to switch to using diagrams as a backend, hence getting a whole bunch of actual backends for free. I would love to see development of some good Haskell font packages -- maybe it would even make a good GSoC project? Unfortunately I don't know enough about it to even know what would be involved, or how much work it would be. I assume that to use diagram the font package would have to be a vector font system, or could bit-mapped fonts be used ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
On Mon, Mar 4, 2013 at 12:07 AM, Ertugrul Söylemez e...@ertes.de wrote: Arie Peterson ar...@xs4all.nl wrote: Would anyone have a problem with a deprecation of MonadCatchIO-transformers, and a failure to update it to work with a base without 'block' and 'unblock'? Yes. This is a simplified variant of a monad I use: newtype Continue f m a = Continue (m (Maybe a, f (Continue f a))) It's related to Cofree and has a valid and very straightforward MonadCatchIO instance. However, it's probably impossible to write a valid MonadTransControl/MonadBaseControl instance for it. So I kindly ask you not to deprecate MonadCatchIO. The reason I'm hesitant about moving to monad-control is that it's hard to understand and also very difficult to define for CPS monads. It is commonly believed to be impossible. You can always cast the continuation to a dynamic type and cast it back later. Doing so would typically require additional constraints, however if you're trying to make an instance for MonadTransControl that's unfortunately not possible (you'd need a Typeable constraint on the monad parameter, but it's not in scope). Lacking an appropriate MonadTransControlWithTypeable class, it's certainly possible to fall back to various low-level, highly-dubious constructs. Which I of course implemented without hesitation :grin Also I've seen at least one article about the incorrectness of monad-control. That's one further reason I like to avoid it. I'd appreciate a link if anyone could manage to find it. I haven't seen any criticisms of monad-control. John L. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Future of MonadCatchIO
Also I've seen at least one article about the incorrectness of monad-control. That's one further reason I like to avoid it. I'd appreciate a link if anyone could manage to find it. I haven't seen any criticisms of monad-control. Oddly, I just stumbled across http://blog.ezyang.com/2012/01/monadbasecontrol-is-unsound/ from a mostly-unrelated search. Was this the article to which you're referring? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple way to do something like ArrowChoice.right on a Conduit? (version 1.0.0)
Thanks for the response. I spent some time thinking about leftovers and understand the Category issue now. Thanks for clearing that up. While trying to work conduits into a program I'm working on, I find myself wanting something more powerful: a resumable Conduit. For example, consider receiving a stream of messages over a network: data Message = Data ByteString | CompressedData ByteString | RestartCompressor When CompressedData is received, feed the bytes to a decompressor conduit. When RestartCompressor is received, close the first decompressor conduit and fire up a new one. Supporting restarts needs more than just Conduit i m o - Conduit (Either x i) m (Either x o). It involves opening and closing a conduit within another conduit's operations. Here's a possible API for a resumable Conduit: newtype ResumableConduit i m o = -- hidden -- newResumableConduit :: Monad m = Conduit i m o - ResumableConduit i m o -- | Feed the 'Source' through the conduit, and send any output from the -- conduit to the 'Sink'. When the 'Sink' returns, close the 'Source', but -- leave the 'ResumableConduit' open so more data can be passed through it. runResumableConduit :: Monad m = ResumableConduit i m o - Source m i - Sink o m r - m (ResumableConduit i m o, r) -- | Tell the conduit there is no more input available, and send the remaining -- output (if any) to the 'Sink'. closeResumableConduit :: Monad m = ResumableConduit i m o - Sink o m r - m r Does anyone want to comment on this interface? Perhaps conduit could have a module called Data.Conduit.Resumable that contains ResumableSource, ResumableConduit, and ResumableSink. The conduit-resumablesink package by Andrew Miller [1] implements ResumableSink; it just needs to be updated for conduit 1.0. [1]: http://hackage.haskell.org/package/conduit-resumablesink ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] simple parsec question
Immanuel, I tried but I couldn't figure it out. Here's a gist with my attempts and results so far: https://gist.github.com/achudnov/f3af65f11d5162c73064 There, 'test' uses my attempt at specifying the parser, 'test2' uses yours. Note that your attempt wouldn't parse multiple sections -- for that you need to use 'many section' instead of just 'section' in 'parse' ('parseFromFile' in the original). I think what's going on is the lookahead is wrong, but I'm not sure how exactly. I'll give it another go tomorrow if I have time. /Andrey On 03/03/2013 05:16 PM, Immanuel Normann wrote: Andrey, Thanks for your attempt, but it doesn't seem to work. The easy part is the headline, but the content makes trouble. Let me write the code a bit more explicit, so you can copy and paste it: -- {-# LANGUAGE FlexibleContexts #-} module Main where import Text.Parsec data Top = Top String deriving (Show) data Content = Content String deriving (Show) data Section = Section Top Content deriving (Show) headline :: Stream s m Char = ParsecT s u m Top headline = manyTill anyChar (char ':' newline) = return . Top content :: Stream s m Char = ParsecT s u m Content content = manyTill anyChar (try headline) = return . Content section :: Stream s m Char = ParsecT s u m Section section = do {h - headline; c - content; return (Section h c)} -- Assume the following example text is stored in /tmp/test.txt: --- top 1: some text ... bla top 2: more text ... bla bla --- Now I run the section parser in ghci against the above mentioned example text stored in /tmp/test.txt: *Main parseFromFile section /tmp/test.txt Right (Section (Top top 1) (Content )) I don't understand the behaviour of the content parser here. Why does it return ? Or perhaps more generally, I don't understand the manyTill combinator (though I read the docs). Side remark: of cause for this little task it is probably to much effort to use parsec. However, my content in fact has an internal structure which I would like to parse further, but I deliberately abstracted from these internals as they don't effect my above stated problem. Immanuel 2013/3/3 Andrey Chudnov achud...@gmail.com mailto:achud...@gmail.com Immanuel, Since a heading always starts with a new line (and ends with a colon followed by a carriage return or just a colon?), I think it might be useful to first separate the input into lines and then classify them depending on whether it's a heading or not and reassemble them into the value you need. You don't even need parsec for that. However, if you really want to use parsec, you can write something like (warning, not tested): many $ liftM2 Section headline content where headline = anyChar `manyTill` (char ':' spaces newline) content = anyChar `manyTill` (try $ newline headline) /Andrey On 3/3/2013 10:44 AM, Immanuel Normann wrote: I am trying to parse a semi structured text with parsec that basically should identify sections. Each section starts with a headline and has an unstructured content - that's all. For instance, consider the following example text (inside the dashed lines): --- top 1: some text ... bla top 2: more text ... bla bla --- This should be parsed into a structure like this: [Section (Top 1) (Content some text ... bla), Section (Top 1) (Content more text ... bla)] Say, I have a parser headline, but the content after a headline could be anything that is different from what headline parses. How could the section parser making use of headline look like? My idea would be to use the manyTill combinator, but I dont find an easy solution. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] building darcs failed (Unable to link against the iconv library)
On 03/03/2013 11:09 PM, Brandon Allbery wrote: On Sun, Mar 3, 2013 at 1:59 PM, Dmitry Malikov malikov@gmail.com mailto:malikov@gmail.com wrote: On 03/03/2013 10:56 PM, Brandon Allbery wrote: On Sun, Mar 3, 2013 at 10:21 AM, Dmitry Malikov malikov@gmail.com mailto:malikov@gmail.com wrote: checking whether to use -liconv... setup: Unable to link against the iconv library. What is actually going on here? Iconv libraries already installed with libc6 package. Linux distinguishes between runtime and linkable libraries; you probably need to install the libc6-dev package to get the latter. (This is not a Haskell-specific issue; configure is using a C But libc6-dev is already the newest version. Then you'll have to check config.log (this probably means doing the build manually with cabal unpack darcs and then running cabal install without a package name from the directory with the darcs.cabal file) to see what's going wrong. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com mailto:allber...@gmail.com ballb...@sinenomine.net mailto:ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net The whole reason of that strange behavior was old libcurl lib or the missed curl-dev lib. I update licurl4-gnutls-dev from libcurl3-gnutls and it pass. -- Best regards, dmitry malikov ! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe