[Haskell-cafe] a little parsec enhancement
Hi, when thinking about this SO question http://stackoverflow.com/q/18583416/1333025, I couldn't find a combinator that allows a parser to /optionally/ fail without consuming input, or consume input and return its value. So I'm suggesting such a function: |-- | @emptyIf p@ parses @p@ and if its return value is @Nothing@, pretends -- that an error has occured with no input consumed. -- -- If @p@ fails and consumes some input, so does @emptyIf p@. Combine with -- 'try' if this is undesirable. emptyIf :: (Stream s m t) =ParsecT s u m (Maybe a) -ParsecT s u m a emptyIf p =ParsecT $ \s cok cerr eok eerr - let cok' (Just x) s e = cok x s e cok'Nothing _ e = eerr e eok' (Just x) s e = eok x s e eok'Nothing _ e = eerr e in unParser p s cok' cerr eok' eerr| With this function, the answer to the SO question becomes really easy: |rcomb :: (Stream s m t) =ParsecT s u m a -ParsecT s u m b -ParsecT s u m b rcomb p q = emptyIf $ runMaybeT (opt p * opt q) where opt =MaybeT . optional-- optional from Control.Applicative!| Whenever |p| or |q| fails without consuming input, then |rcomb p q| fails without consuming input. Unfortunately |ParsecT| constructor isn't exported so I'm not able to implement it outside /parsec/. (Perhaps it would make sense to export |ParsecT| in some module such as |Text.Parsec.Internal|?) Therefore I'm suggesting to add such a function to /parsec/ (darcs patch included). Perhaps change the name, I couldn't think of anything better. Best regards, Petr 1 patch for repository http://code.haskell.org/parsec3: Thu Sep 5 11:12:47 CEST 2013 Petr Pudlak p...@pudlak.name * Add 'emptyIf' which allows a parser to optinally fail without consuming any input. New patches: [Add 'emptyIf' which allows a parser to optinally fail without consuming any input. Petr Pudlak p...@pudlak.name**20130905091247 Ignore-this: 59b93c660fe860acd9a5fff887f7678f ] { hunk ./Text/Parsec/Prim.hs 38 , parserPlus , (?) , (|) +, emptyIf , label , labels , lookAhead hunk ./Text/Parsec/Prim.hs 455 p' = ParsecT $ \s cok cerr eok eerr - unParser p s eok cerr eok eerr +-- | @emptyIf p@ parses @p@ and if its return value is @Nothing@, pretends +-- that an error has occured with no input consumed. +-- +-- If @p@ fails and consumes some input, so does @emptyIf p@. Combine with +-- 'try' if this is undesirable. + +emptyIf :: (Stream s m t) = ParsecT s u m (Maybe a) - ParsecT s u m a +emptyIf p = ParsecT $ \s cok cerr eok eerr - +let cok' (Just x) s e = cok x s e +cok' Nothing _ e = eerr e +eok' (Just x) s e = eok x s e +eok' Nothing _ e = eerr e +in unParser p s cok' cerr eok' eerr + + -- | The parser @token showTok posFromTok testTok@ accepts a token @t@ -- with result @x@ when the function @testTok t@ returns @'Just' x@. The -- source position of the @t@ should be returned by @posFromTok t@ and } Context: [Fix haddock module links. Bjorn Buckwalter bj...@buckwalter.se**20130821095713 Ignore-this: 304217ec8b73f59edcd96dd13aca67af ] [TAG 3.1.3 Antoine Latter aslat...@gmail.com**20120612020909 Ignore-this: 7100375a3e4853c09f1ea993ae32eed7 ] Patch bundle hash: 173111b8bbc5a6eb69d41926053184c35ae9b3cc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial on JS with Haskell: Fay or GHCJS?
On 09/04/2013 05:39 PM, Adam Bergmark wrote: Here are some points I'd like to emphasize in addition to the threads above, with the disclaimer that I'm the maintainer of Fay. Fay tries to be very simple, the code base is small (~4800 LoC). This really lowers the entry barrier for contributions which I think is very important for open source projects. GHCJS is much more complicated since it tries to do so much. For GHCJS I'd be afraid that the developers might eventually abandon the project and then it'd be pretty hard to take over development. Much easier for someone to take over Fay development. I think you can safely expect to find bugs in all compilers, and if you do and you are in a hurry you might have to fix it yourself. Fay has very simple output that is close to both Haskell and JavaScript so it's pretty easy to just add a breakpoint and start debugging. Even if GHCJS can successfully compile most of hackage, would we want to have these as dependencies in web projects? An output size of 1MiB is nothing when compiling a binary, but for a public website 1MiB can still be quite a lot, add some transitive dependencies and output will explode. Most people don't optimize their packages to have few dependencies, which makes sense since the abstraction usually heavily outweighs code size. So either way you would probably want to write some specific light-weight versions of libraries you want to use, that's one reason both GHCJS and Fay have their own base packages. One place I think GHCJS can shine is for non standard web applications such as WEBGL games. Nothing stopping you from using Fay for this, but I expect you can really start to leverage GHCJS's threaded runtime here. Hi Adam! We found it to be very convenient to use both Hastec and Fay. Since the former (as well, as GHCJS) is based on GHC, you can be quite sure any bugs you encounter are yours, not of the compiler. And after your code works with Hastec and so your idea is tested, you can try to port it to Fay. Usually it's trivial, but prepare to encounter some minor compiler deficiencies here and there. So my proposal to original poster would be to tell a bit about both. After all, they represent different approaches to JS generation each with it's own pros and cons. Regards, Dmitry ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a little parsec enhancement
* Petr Pudlák petr@gmail.com [2013-09-05 11:18:25+0200] Unfortunately |ParsecT| constructor isn't exported so I'm not able to implement it outside /parsec/. No, but there's an 'mkPT' function which is equivalent to the ParsecT constructor. (Although I, too, wish the ParsecT constructor were exposed.) Roman signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Cabal v1.18.0 released
On Wednesday, September 4, 2013 11:41:33 PM UTC+2, Yuri de Wit wrote: Thanks for all the hard work! If you see this in OSX (#1009) while installing cabal 1.18: *Warning: could not create a symlink in /Users/lemao/Library/Haskell/bin for* *cabal because the file exists there already but is not managed by cabal. You* *can create a symlink for this executable manually if you wish. The executable* *file has been installed at* */Users/user/Library/Haskell/ghc-7.6.3/lib/cabal-install-1.18.0/bin/cabal* You will need to manually remove the pre-existing 1.16 links in ~/Library/Haskell/bin before installing again. Instead of installing again, you can even just recreate the symlink as mentioned by the message (if you know how to do that). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell-Cafe Digest, Vol 121, Issue 8
Hi all, On behalf of the cabal maintainers and contributors I'm proud to announce the Cabal (and cabal-install) 1.18.0 release. To install run cabal update cabal install Cabal-1.18.0 cabal-install-1.18.0 With 854 commits since the last release there are two many improvements and bug fixes to list them here, but two highlights are: * Hermetic builds using sandboxes. This should reduce the number of dependency hell and broken package DB problems. [] I was quite happy to hear of the new cabal - and the chance to escape the various mazes of cabal-dependency problems. But I seem to have a bootstrapping problem, the new cabal won't install to help me get out of its messes! I tried to install what I thought were its complaints (below), and they seemed OK - any hints? The key problem seems to be: mtl-2.1.2-5337caef659244e51e2f5fb2e944d97f is shadowed by package mtl-2.1.2-678980f6077e9f83a86186556aa2a425 Not sure how this happened, or how to remedy it. Cabal FAQ says to unregister the user database version, but that notes that it would break about 20+ other packages, but do it anyway. So yes, I did and now have a bigger mess it seems. Now mtl install gives: Building mtl-2.1.2... Preprocessing library mtl-2.1.2... Bad interface file: E:\Plang\Haskell Platform\lib\extralibs\transformers-0.3.0.0\ghc-7.4.2\Control\Monad\Trans\Error.hi mismatched interface file versions (wanted 7063, got 7042) Failed to install mtl-2.1.2 cabal: Error: some packages failed to install: mtl-2.1.2 failed during the building phase. The exception was: ExitFailure 1 I am reluctant to do a clean restart install, since it was so much trouble building some packages like wx and other graphics .dll packages. Argh... --- C:\Users\guthriecabal update Downloading the latest package list from hackage.haskell.org Note: there is a new version of cabal-install available. To upgrade, run: cabal install cabal-install C:\Users\guthriecabal install cabal-install Resolving dependencies... Downloading Cabal-1.18.0... [ 1 of 70] Compiling Distribution.PackageDescription.Utils ... [70 of 70] Compiling Main ( C:\Users\guthrie\AppData\Local\Temp\Cabal-1.18.0-13108\Cabal-1.18.0\Setup.hs, C:\Users\guthrie\AppData\Local\Temp\Cabal-1.18.0-13108\Cabal-1.18.0\dist\setup\Main.o ) Linking C:\Users\guthrie\AppData\Local\Temp\Cabal-1.18.0-13108\Cabal-1.18.0\dist\setup\setup.exe ... Configuring Cabal-1.18.0... Building Cabal-1.18.0... Preprocessing library Cabal-1.18.0... [ 1 of 72] Compiling Paths_Cabal ... Distribution\Version.hs:125:1: Warning: Orphan instance: instance Data Version In-place registering Cabal-1.18.0... Installing library in C:\Users\guthrie\AppData\Roaming\cabal\i386-windows-ghc-7.6.3\Cabal-1.18.0 Registering Cabal-1.18.0... Installed Cabal-1.18.0 Downloading cabal-install-1.18.0... Configuring cabal-install-1.18.0... Warning: This package indirectly depends on multiple versions of the same package. This is highly likely to cause a compile failure. ... package mtl-2.1.2 requires transformers-0.3.0.0 package mtl-2.1.2 requires transformers-0.3.0.0 Building cabal-install-1.18.0... Preprocessing executable 'cabal' for cabal-install-1.18.0... command line: cannot satisfy -package-id mtl-2.1.2-5337caef659244e51e2f5fb2e944d97f: mtl-2.1.2-5337caef659244e51e2f5fb2e944d97f is shadowed by package mtl-2.1.2-678980f6077e9f83a86186556aa2a425 (use -v for more information) Failed to install cabal-install-1.18.0 cabal: Error: some packages failed to install: cabal-install-1.18.0 failed during the building phase. The exception was:ExitFailure 1 C:\Users\guthriecabal install mtl Resolving dependencies... All the requested packages are already installed: mtl-2.1.2 Use --reinstall if you want to reinstall anyway. C:\Users\guthriecabal install transformers Resolving dependencies... All the requested packages are already installed: transformers-0.3.0.0 Use --reinstall if you want to reinstall anyway. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Cabal v1.18.0 released
It is easy enough to recreate the link manually or as easy to run cabal install again, but that is not the point here. The point is that it will bite the next dozen of unsuspecting users since, at first, they have no idea of what is going on. In any case, apologies for sending this in this thread as it doesn't seem the right forum to discuss it. On Thu, Sep 5, 2013 at 7:53 AM, Paolo Giarrusso p.giarru...@gmail.comwrote: On Wednesday, September 4, 2013 11:41:33 PM UTC+2, Yuri de Wit wrote: Thanks for all the hard work! If you see this in OSX (#1009) while installing cabal 1.18: *Warning: could not create a symlink in /Users/lemao/Library/Haskell/bin for* *cabal because the file exists there already but is not managed by cabal. You* *can create a symlink for this executable manually if you wish. The executable* *file has been installed at* */Users/user/Library/Haskell/ghc-7.6.3/lib/cabal-install-1.18.0/bin/cabal * You will need to manually remove the pre-existing 1.16 links in ~/Library/Haskell/bin before installing again. Instead of installing again, you can even just recreate the symlink as mentioned by the message (if you know how to do that). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Performance of delete-and-return-last-element
Dne 09/01/2013 09:13 PM, Harald Bögeholz napsal(a): Am 31.08.13 14:35, schrieb Petr Pudlák: One solution would be to fold over a specific semigroup instead of a recursive function: |import Data.Semigroup import Data.Foldable(foldMap) import Data.Maybe(maybeToList) data Darle a =Darle {getInit :: [a],getLast ::a } deriving Show instance Semigroup (Darle a)where ~(Darle xs1 l1) ~(Darle xs2 l2) =Darle (xs1 ++ [l1] ++ xs2) l2 darle :: [a] -Darle a darle = foldr1 () . map (Darle [])| It's somewhat more verbose, but the core idea is clearly expressed in the one line that defines ||, and IMHO it better shows /what/ are we doing rather than /how/. It's sufficiently lazy so that you can do something like |head . getInit $ darle [1..]|. I am wondering why you put the Semigroup instance there and what the other imports are for. Doesn't this work just as well? Sorry, the two other imports are redundant, I forgot to erase them when playing with various ideas. The Semigroup instance of course isn't necessary for this particular purpose. But having it (1) signals that the operation satisfies some laws (associativity) and (2) allows the structure to be reused anywhere where a Semigroup is required. For example, we can wrap it into `Option` to get a monoid, and perhaps use it in `foldMap`. This way we extend the functionality to empty collections: ```haskell darle :: Foldable f = f a - Maybe (Darle a) darle = getOption . foldMap (Option . Just . Darle []) ``` Best regards, Petr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Cabal v1.18.0 released
I ran into another oddity due to old build artifacts today -- it was easy to fix, but very confusing; cabal repl was exiting with unrecognised command: repl. tl/dr; if you see this, delete the old 'dist' dir and re-run 'cabal configure'. Here's a snippit of my shell session to explain in more detail: $ cabal sandbox init ... $ cabal --version cabal-install version 1.18.0 using version 1.18.0 of the Cabal library $ cabal configure Resolving dependencies... Configuring pgftransform-0.0.0.1... $ cabal repl unrecognised command: repl (try --help) $ cabal --help ... Commands: ... buildCompile all targets or specific targets. repl Open an interpreter session for the given target. sandbox Create/modify/delete a sandbox. ... Note that cabal --version and cabal --help indicated that repl /was/ a valid command. The issue appears to be that an old dist directory was still hanging around, and (I suspect) the compiled setup.hs build program (which would have been built with an old Cabal) was causing the actual error. Deleting the dist dir and re-running cabal configure set everything right. --Rogan On Thu, Sep 5, 2013 at 6:18 AM, Yuri de Wit yde...@gmail.com wrote: It is easy enough to recreate the link manually or as easy to run cabal install again, but that is not the point here. The point is that it will bite the next dozen of unsuspecting users since, at first, they have no idea of what is going on. In any case, apologies for sending this in this thread as it doesn't seem the right forum to discuss it. On Thu, Sep 5, 2013 at 7:53 AM, Paolo Giarrusso p.giarru...@gmail.comwrote: On Wednesday, September 4, 2013 11:41:33 PM UTC+2, Yuri de Wit wrote: Thanks for all the hard work! If you see this in OSX (#1009) while installing cabal 1.18: *Warning: could not create a symlink in /Users/lemao/Library/Haskell/bin for* *cabal because the file exists there already but is not managed by cabal. You* *can create a symlink for this executable manually if you wish. The executable* *file has been installed at* */Users/user/Library/Haskell/ghc-7.6.3/lib/cabal-install-1. 18.0/bin/cabal* You will need to manually remove the pre-existing 1.16 links in ~/Library/Haskell/bin before installing again. Instead of installing again, you can even just recreate the symlink as mentioned by the message (if you know how to do that). ___ 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] ANN: Cabal v1.18.0 released
I pasted your report into the bug tracker: https://github.com/haskell/cabal/issues/1478 I don't know if you're on GitHub or not so I could link the report to your user. On Thu, Sep 5, 2013 at 8:16 AM, Rogan Creswick cresw...@gmail.com wrote: I ran into another oddity due to old build artifacts today -- it was easy to fix, but very confusing; cabal repl was exiting with unrecognised command: repl. tl/dr; if you see this, delete the old 'dist' dir and re-run 'cabal configure'. Here's a snippit of my shell session to explain in more detail: $ cabal sandbox init ... $ cabal --version cabal-install version 1.18.0 using version 1.18.0 of the Cabal library $ cabal configure Resolving dependencies... Configuring pgftransform-0.0.0.1... $ cabal repl unrecognised command: repl (try --help) $ cabal --help ... Commands: ... buildCompile all targets or specific targets. repl Open an interpreter session for the given target. sandbox Create/modify/delete a sandbox. ... Note that cabal --version and cabal --help indicated that repl /was/ a valid command. The issue appears to be that an old dist directory was still hanging around, and (I suspect) the compiled setup.hs build program (which would have been built with an old Cabal) was causing the actual error. Deleting the dist dir and re-running cabal configure set everything right. --Rogan On Thu, Sep 5, 2013 at 6:18 AM, Yuri de Wit yde...@gmail.com wrote: It is easy enough to recreate the link manually or as easy to run cabal install again, but that is not the point here. The point is that it will bite the next dozen of unsuspecting users since, at first, they have no idea of what is going on. In any case, apologies for sending this in this thread as it doesn't seem the right forum to discuss it. On Thu, Sep 5, 2013 at 7:53 AM, Paolo Giarrusso p.giarru...@gmail.com wrote: On Wednesday, September 4, 2013 11:41:33 PM UTC+2, Yuri de Wit wrote: Thanks for all the hard work! If you see this in OSX (#1009) while installing cabal 1.18: Warning: could not create a symlink in /Users/lemao/Library/Haskell/bin for cabal because the file exists there already but is not managed by cabal. You can create a symlink for this executable manually if you wish. The executable file has been installed at /Users/user/Library/Haskell/ghc-7.6.3/lib/cabal-install-1.18.0/bin/cabal You will need to manually remove the pre-existing 1.16 links in ~/Library/Haskell/bin before installing again. Instead of installing again, you can even just recreate the symlink as mentioned by the message (if you know how to do that). ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Reminder to file Haddock bugs on Trac.
This is just a friendly reminder that if you have any issues with Haddock that you would like to get looked at, you should probably be making your way to the Haddock Trac[1] now. If you already have open tickets, you can probably get them looked at if you reply to this thread. Unfortunately there are a lot of old tickets so it's difficult to tell what's still desired, what's still a problem, what has been solved outside of Trac and not marked and so on. Thanks! [1]: http://trac.haskell.org/haddock/ -- Mateusz K. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Cabal v1.18.0 released
Hideyuki Tanaka was missing from the list of contributors (his patch was applied through me). His contribution made 'cabal update' faster! On Wed, Sep 4, 2013 at 2:11 PM, Johan Tibell johan.tib...@gmail.com wrote: Hi all, On behalf of the cabal maintainers and contributors I'm proud to announce the Cabal (and cabal-install) 1.18.0 release. To install run cabal update cabal install Cabal-1.18.0 cabal-install-1.18.0 With 854 commits since the last release there are two many improvements and bug fixes to list them here, but two highlights are: * Hermetic builds using sandboxes. This should reduce the number of dependency hell and broken package DB problems. * GHCi support. It's now much easier to use ghci when developing your packages, especially if those packages require preprocessors (e.g. hsc2hs). Here's how working on a package might look like using the new features: # Only once: cabal sandbox init cabal install --only-dependencies --enable-tests # Configure, build, and run tests: cabal test # now implies configure and build # Play around with the code in GHCi: cabal repl Mikhail wrote a bit more about the user visible changes on his blog: http://coldwa.st/e/blog/2013-08-21-Cabal-1-18.html For a complete list of changes run git log cabal-install-v1.16.0.2..cabal-install-v1.18.0 in the cabal repo or look at the GitHub compare page: https://github.com/haskell/cabal/compare/cabal-install-v1.16.0.2...cabal-install-v1.18.0 (only shows the last 250 commits). 57 people contributed to this release! 503 Mikhail Glushenkov 99 Johan Tibell 41 Duncan Coutts 39 Ian Lynagh 19 Brent Yorgey 19 Thomas Tuegel 18 Ben Millwood 16 Eyal Lotem 10 Thomas Dziedzic 7 Andres Loeh 6 John Wiegley 6 Benno Fünfstück 5 Gregory Collins 4 Herbert Valerio Riedel 4 Simon Hengel 3 Joachim Breitner 3 Luke Iannini 3 Bryan Richter 3 Richard Eisenberg 3 Tuncer Ayaz 3 Jens Petersen 2 Arun Tejasvi Chaganty 2 Bryan O'Sullivan 2 Eric Kow 2 Jookia 2 Paolo G. Giarrusso 2 Paolo Capriotti 1 Sönke Hahn 1 Yitzchak Gale 1 Albert Krewinkel 1 stepcut 1 Alexander Kjeldaas 1 Austin Seipp 1 Bardur Arantsson 1 Ben Doyle 1 Ben Gamari 1 Bram 1 Carter Tazio Schonwald 1 Clint Adams 1 Daniel Wagner 1 David Lazar 1 Erik Hesselink 1 Eugene Sukhodolin 1 Gabor Greif 1 Jack Henahan 1 Jason Dagit 1 Ken Bateman 1 Mark Lentczner 1 Masahiro Yamauchi 1 Merijn Verstraaten 1 Michael Thompson 1 Niklas Hambüchen 1 Oleksandr Manzyuk 1 Patrick Premont 1 Roman Cheplyaka 1 Sergei Trofimovich 1 Stephen Blackheath -- Johan, on behalf of the cabal maintainers and contributors. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ghc-mod v3.0.0
Hi all, I have just uploaded ghc-mod v3.0.0 to Hackage. In this version, ghc-mod supports the sandbox feature of cabal-install. Instead, it stopped supporting cabal-dev. If you want to use ghc-mod v3.0.0, I would recommand to install cabal-install 1.18. The sandbox in your package is automatically detected by ghc-mod if exists. --Kazu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe