trivial function application question

greetings to this helpful and informative list i have a small problem that will be certainly trivial for almost everyone reading this, i would appreciate a little help lets say i have a string s = "abcdefg" now i have two lists of strings, one a list of patterns to match, and a list of replacement strings: patterns = ["a","b"] replace = ["Z","Y"] from which my intent is that "a" be replaced by "Z", "b" by "Y" etc now using the replace function from MissingH.Str (which i know is now renamed), i wish to apply replace to s using (pattern[0], replace[0]), (pattern[1], replace[1])...(pattern[N], replace[N]). i am sure there is an elegant way to apply replace to s for all of these argument pairs without composing replace N times myself, but the solution escapes me. thanks in advance for any help you can provide for this trivial issue brad

Hi Brad,
i have a small problem that will be certainly trivial for almost everyone reading this, i would appreciate a little help
If you have trivial problems, its often useful to ask on Haskell IRC (http://www.haskell.org/haskellwiki/IRC_channel)
from which my intent is that "a" be replaced by "Z", "b" by "Y" etc
i am sure there is an elegant way to apply replace to s for all of these argument pairs without composing replace N times myself, but the solution escapes me.
In your example all "strings" are one letter long, is that how this works? If so, then you can simplify the problem significantly to use Char's, and use the following library functions: First off, if you want to apply the same "transformation" to each item of a list, namely to either replace it or leave it the same. This calls out for map. Secondly you want to do lookups in some sort of table. The lookup function can be very handy here. The lookup function works on associative lists, so you'd need to zip patterns and replace into an associative list. If you really want to operate on strings, rather than characters, then you have to be more clever. Also replace called multiple times probably won't be enough, consider replacing 1 with 2, 2 with 3. If you just call replace multiple times, 1 may well end up at 3, when 2 is more likely to be the right answer. Thanks Neil

On 1/4/07, brad clawsie
lets say i have a string
s = "abcdefg"
now i have two lists of strings, one a list of patterns to match, and a list of replacement strings:
patterns = ["a","b"] replace = ["Z","Y"]
from which my intent is that "a" be replaced by "Z", "b" by "Y" etc
now using the replace function from MissingH.Str (which i know is now renamed), i wish to apply replace to s using (pattern[0], replace[0]), (pattern[1], replace[1])...(pattern[N], replace[N]).
You can create the replacing functions using zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] (from the Prelude) as follows: replacers = zipWith patterns replace You then need to apply these functions to your starting string s. I would probably use foldr for that, something like this: foldr ($) s replacers Where ($) performs function application. As Neil points out, if your replacements overlap, this could cause replacement text to itself be replaced. /g -- It is myself I have never met, whose face is pasted on the underside of my mind.

Oops, I seem not to have proofread my message.
On 1/4/07, J. Garrett Morris
On 1/4/07, brad clawsie
wrote: s = "abcdefg" patterns = ["a","b"] replacements = ["Z","Y"]
I changed the name here so as not to conflict with the replace function. <snip>
You can create the replacing functions using zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] (from the Prelude) as follows:
replacers = zipWith replace patterns replacements
This line was previously incorrect. /g

So the core question (speaking as a perler) is how do you write my $s= 'abcdefg'; $s =~ s/a/z/g; $s =~ s/b/y/g; print "$s\n"; in haskell? There are various haskell regex libraries out there, including ones that advertise they are PCRE (Perl Compatible Reg Ex). But which one to use? How hard to install? With the libs mentioned above, the "PCRE"-ness seems only to be for matching, not for substitutions. http://www.cs.chalmers.se/~d00nibro/harp/ http://repetae.net/john/computer/haskell/JRegex/ So, I would like to know a good answer to this as well. thomas. brad clawsie-2 wrote:
greetings to this helpful and informative list
i have a small problem that will be certainly trivial for almost everyone reading this, i would appreciate a little help
lets say i have a string
s = "abcdefg"
now i have two lists of strings, one a list of patterns to match, and a list of replacement strings:
patterns = ["a","b"] replace = ["Z","Y"]
from which my intent is that "a" be replaced by "Z", "b" by "Y" etc
now using the replace function from MissingH.Str (which i know is now renamed), i wish to apply replace to s using (pattern[0], replace[0]), (pattern[1], replace[1])...(pattern[N], replace[N]).
i am sure there is an elegant way to apply replace to s for all of these argument pairs without composing replace N times myself, but the solution escapes me.
thanks in advance for any help you can provide for this trivial issue brad
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/trivial-function-application-question-tf2922232.html#a... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

tphyahoo wrote:
So the core question (speaking as a perler) is how do you write
my $s= 'abcdefg'; $s =~ s/a/z/g; $s =~ s/b/y/g; print "$s\n";
in haskell? There are various haskell regex libraries out there,
But that's such a perler attitude. When all you have is a regex, everything looks like a s///! This really doesn't look like much of a regex question to me. A more haskelly answer might be as simple as: m 'a' = 'z' m 'b' = 'y' m x = x test1 = map m "abcdefg" ...which is general in the sense that 'm' can be an arbitrary function from Char -> Char, and avoids the 'overlapping replace' behaviour alluded to elsewhere in this thread, but is limited if you wanted to do string-based replacement. To do string-based replacement you do have to think careful about what semantics you're expecting though (w.r.t. overlapping matches, repeated matches, priority of conflicting matches). Jules

yes, I admit it's a perler attitude. I still want to know how to do "s///" in haskell. My guess is that for a "real" regex substitution scenario, you would use parsec. Is that more or less correct, or are there other (easier?) approaches. It would of course be great to be able to transfer as much of my PCRE domain experience as possible to haskell. eg in perl: use strict; use warnings; # phone numbers my $strings = [ "123 456 7890", "123 456 7890", "blah", "789 234 1" ]; for my $string ( @$strings ) { my $formatted = tel_num($string); print "$formatted\n" if $formatted; } sub tel_num { my $string = shift or die "no string"; return unless $string =~ /(\d\d\d)\s+(\d\d\d)\s+(\d\d\d\d)/; return "$1-$2-$3" } outputs (not just identified match, prettied up as well): 123-456-7890 123-456-7890 so, best done with parsec, or some other way? Jules Bean wrote:
tphyahoo wrote:
So the core question (speaking as a perler) is how do you write
my $s= 'abcdefg'; $s =~ s/a/z/g; $s =~ s/b/y/g; print "$s\n";
in haskell? There are various haskell regex libraries out there,
But that's such a perler attitude. When all you have is a regex, everything looks like a s///!
This really doesn't look like much of a regex question to me. A more haskelly answer might be as simple as:
m 'a' = 'z' m 'b' = 'y' m x = x
test1 = map m "abcdefg"
...which is general in the sense that 'm' can be an arbitrary function from Char -> Char, and avoids the 'overlapping replace' behaviour alluded to elsewhere in this thread, but is limited if you wanted to do string-based replacement.
To do string-based replacement you do have to think careful about what semantics you're expecting though (w.r.t. overlapping matches, repeated matches, priority of conflicting matches).
Jules _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/trivial-function-application-question-tf2922232.html#a... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

tphyahoo wrote:
There are various haskell regex libraries out there,
Jules Bean wrote:
But that's such a perler attitude. When all you have is a regex, everything looks like a s///!
Not always, sometimes it is right to use regexes in Haskell also. If there are more than a few patterns to match in the same string, or if the patterns are more than a few characters long, then the simple approach will start becoming expensive. You need to use a more sophisticated algorithm - building up trees of potential matches, backtracking in some cases, etc. Why re-invent the wheel? Just use the regex library, where that is already done. Regards, Yitz

Yitzchak Gale wrote:
You need to use a more sophisticated algorithm - building up trees of potential matches, backtracking in some cases, etc. Why re-invent the wheel? Just use the regex library, where that is already done.
It's merely a question of selecting the right wheel. Some problems are so simple that regexes are overkill. Some problems are so complex that regexes are insufficient. Some problems generate extraordinarily ugly regexes, which are then hard-to-debug. Some problems are perfectly suited to regexes. Jules

On Jan 5, 2007, at 9:38 , Jules Bean wrote:
Yitzchak Gale wrote:
You need to use a more sophisticated algorithm - building up trees of potential matches, backtracking in some cases, etc. Why re-invent the wheel? Just use the regex library, where that is already done.
It's merely a question of selecting the right wheel. Some problems are so simple that regexes are overkill. Some problems are so complex that regexes are insufficient. Some problems generate extraordinarily ugly regexes, which are then hard-to-debug.
I will note that the most common use for regexes in Perl is for parsing (which is why perl6 has generalized regexes into a parsing mechanism). -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

It would seem that for a regular expression facility to constitute a parser it would have to be able to work on token streams. So my question is, does either the the perl6 generalization or any of the Haskell regex facilities support regular expressions over any free monoid other than finite character sequences? -- Bill Wood

Bill Wood wrote:
It would seem that for a regular expression facility to constitute a parser it would have to be able to work on token streams. So my question is, does either the the perl6 generalization or any of the Haskell regex facilities support regular expressions over any free monoid other than finite character sequences?
-- Bill Wood
Currently: The regular expressions themselves are finite, but some Haskell regex-* backend packages can run searches on "infinite" [Char], since they are lazy. This is true of regex-parsec and regex-dfa. In particular they take care not to consume extra Char's from the input stream, though Parsec insists on looking at the next character. The regex-base type class API in Text.Regex.Base.RegexLike does not limit you to any particular source of the regex or any particular type of thing to be searched. There is a limit that comes from using Int as the index of choice. If you are searching something more that 2 billion units long then you would run into API problems. (One could just make a parallel BigRegex type class API and make instances for it for the backends that can handle it. ). Or I may expand it to take any (Num). Hmmm..... Specifically, the RegerMaker is parameterized over "source" and "regex" and so is completely generic. This "source" is what specifies how to build the the compiled "regex" opaque type. Specifically, the Extract is parameterized over "source" (but limits the index to Int). This "source" is the type being searched. Specifically, the RegexLike class is parameterized over "regex" and "source", where "regex" is the supposed to be the opaque compiled type from RegexMaker and "source" is the type being searched. Currently the RegexMaker source can be [Char] or ByteString and the RegexLike/Extract "source" can be [Char] or ByteString. Adding (Data.Sequence Char) would make sense, and perhaps (Data.Sequence Word8) as ASCII. If you write a very generic backend then you may be able to make more generic instances of the API. Note that the instances should be obvious because your generic backend uses a unique opaque "regex" type. Also not that the API is named Regex in several places but there is no need to use anything like a Regex syntax. In fact you could use something other than RegexMaker to create the "regex" type used for specifying the searching/matching. I have not considered it until now, but maybe one could create an instance of RegexLike based around Parsec's GenParser. -- Chris

tphyahoo wrote:
So the core question (speaking as a perler) is how do you write
my $s= 'abcdefg'; $s =~ s/a/z/g; $s =~ s/b/y/g; print "$s\n";
in haskell? There are various haskell regex libraries out there, including ones that advertise they are PCRE (Perl Compatible Reg Ex).
I updated the regex libraries for GHC 6.6. ( All the regex-* packages. ) The old API is still supported in Text.Regex. The old API has a replacement function, while the new API does not have one (yet). For simple regular expressions, where Posix and Perl agree, you can just use Text.Regex.subRegex which comes with GHC. In 6.6 this comes in the regex-compat package, and which calls the regex-posix backend via the interfaces defined in regex-base. All of these come with GHC, since GHC needs regex support to compile itself. So if you do not need more syntax than POSIX regex (with back references) then http://www.haskell.org/ghc/docs/latest/html/libraries/regex-compat/Text-Rege... works, but depends on the low performance posix-regex backend. This will run your example above, for instance. Better regex searching performance can be had by using the new interface via Text.Regex.Base with better backends and/or with Data.ByteString. In the future there will be Data.Sequence (of Char and perhaps Word8) support added to the backends. There is no updated API for performing replacements using a pluggable backend. The design space is too large with conflicting needs to be lazy or strict, time or space efficient, etc. The best thing is to write the replacement function that your application needs. You can use the new searching API (see micro-tutorial below) to write a replacement routine in less than a screen of code. For instance, the regex-compat version of Text.Regex.subRegex is
{- | Replaces every occurance of the given regexp with the replacement string.
In the replacement string, @\"\\1\"@ refers to the first substring; @\"\\2\"@ to the second, etc; and @\"\\0\"@ to the entire match. @\"\\\\\\\\\"@ will insert a literal backslash.
This is unsafe if the regex matches an empty string. -} subRegex :: Regex -- ^ Search pattern -> String -- ^ Input string -> String -- ^ Replacement text -> String -- ^ Output string subRegex _ "" _ = "" subRegex regexp inp repl = let bre = mkRegex "\\\\(\\\\|[0-9]+)" lookup _ [] _ = [] lookup [] _ _ = [] lookup match repl groups = case matchRegexAll bre repl of Nothing -> repl Just (lead, _, trail, bgroups) -> let newval = if (head bgroups) == "\\" then "\\" else let index = (read (head bgroups)) - 1 in if index == -1 then match else groups !! index in lead ++ newval ++ lookup match trail groups in case matchRegexAll regexp inp of Nothing -> inp Just (lead, match, trail, groups) -> lead ++ lookup match repl groups ++ (subRegex regexp trail repl)
You could just paste that code into a file that imports a different backend and it should work since it uses just the type class API. You might also improve on the above routine or specialize it. The above handle \0 \1 \2 substitutions (and \\ escaping) in the replacement string, including multi-digit references such as \15 for very large regular expressions. It operation only on [Char] and is somewhat lazy.
But which one to use? How hard to install? With the libs mentioned above, the "PCRE"-ness seems only to be for matching, not for substitutions.
I think if you paste the subRegex code above underneath an "import Text.Posix.PCRE" declaration then you get what you are looking for. To install: The regex-* package hosting is via darcs and has been copied/moved to http://darcs.haskell.org/packages/ (The stable regex-* versions) http://darcs.haskell.org/packages/regex-unstable/ (The unstable regex-* versions) so "darcs get --partial http://darcs.haskell.org/packages/regex-pcre" might be useful. They have (hopefully working) cabal files to make compiling and installing easy. Note that regex-pcre and regex-tre need libpcre and libtre to be installed separately. regex-posix needs a posix library, but GHC already provides this package with a working libary. These 3 come with GHC: regex-base defines the type classes and APIs and most RegexContext instances regex-compat imitates the old Text.Regex API using regex-posix regex-posix backend has awful performance. Not for heavy use. These 4 backends can be downloaded using darcs: regex-pcre uses libpcre and this imitates the PERL search syntaxs and semantics. regex-tre used libtre, a very fast posix-compatible (but LGPL) library. regex-parsec which is not very speedy, but is pure Haskell regex-dfa is pure haskell and fast, but cannot do subexpression capture yet, and has some problems (repeating an empty-matching pattern like "(a*)*" will create an infinite loop in compiling the regex). regex-devel is for hosting test suites and benchmarks. You won't need this.
http://www.cs.chalmers.se/~d00nibro/harp/ http://repetae.net/john/computer/haskell/JRegex/
JRegex is mostly superseded by the more flexible interface of regex-base. This flexibility allowed Data.ByteString to be used for efficiency as well as String. The new API for searching with regex works like this (a micro-tutorial): import Text.Regex.Base import Text.Regex.Posix -- or PCRE or Parsec or TRE or DFA The above should provide (=~) and (=~~) matching operators, which do ("text to be searched" =~ "regex to use") operations. The value returned is any of the instances of RegexContext (See documentation for Text.Regex.Base.Context). So in a numerical context (i.e. you demand an Int type) the search returns the number of matches, and in a more complicated context it returns all matches including all their captures (\0 \1 \2 \3 ...). =~ and =~~ differ in that the second operates in a Monadic context and this has access to a "fail" method when the search does not succeed. But =~ and =~~ are convenience methods for 1st : converting the regex string to a compiled form with 'makeRegex' 2nd : performing the search with 'match' (for =~) or 'matchM' (for =~~) The error handling (such as with a malformed regex) is primitive. The RegexMaker class defines 'makeRegex' as well as a more complicated 'makeRegexOpts' which lets you specify backend specific options (e.g. case-sensitivity). The error handling is primitive. The RegexContext class defines match and matchM which are still at a high level of the API and the return type is polymorphic (i.e. depends on the context of the call much like in PERL). The error handling is primitive. The RegexContext class does its magic by using the RegexLike class methods. The RegexLike methods are a medium level API and are implemented by instances in such modules as Text.Regex.Posix.String and Text.Regex.Posix.ByteString. The RegexMaker 'makeRegex' instances are also defined in these modules. The error handling is primitive. If you import a specific module such as Text.Regex.Posix.String then you can access the three lower-level API functions: 'compile' : used to build makeRegexOpts/makeRegex for RegexMaker 'execute' : used to perform a search and get back offsets and lengths of matching \0 \1 \2, etc, where \0 is the whole match. 'regexec' : used to perform a search and get back the actual substrings: (before match,the whole match,after the match,[list of captured sequences]) These three lower-level API functions are available in all the backends, and use "Either String a" to report errors in a sensible way. If for some very bizarre reason you don't like my API's then you can import whatever modules happen to have the raw API for that backend. For PCRE this is Text.Regex.PCRE.Wrap (which is Wrap.hsc file in the source, not Wrap.hs). This has the FFI interface to the libpcre library and a bunch of haskell enumerations and types defined, and exports functions with names starting with "wrap" that handle correctly calling the c library from Haskell. These are very specific to the PCRE backend, and the errors are always returned in a very detailed way via Either types.
So, I would like to know a good answer to this as well.
thomas.
Feel free to ask for more help and better answer.

Very, very helpful Chris; thanks; and thanks also to the many other helpful haskellers.
They have (hopefully working) cabal files to make compiling and installing ea\ sy.
Unfortunately, not so easy, for PCRE.regex. But hopefully this is just due to my ignorance and there's a simple workaround. At any rate, after darcs --getting as you suggested, I ran make, and got various complaints. I installed haddock, happy, alex, hat, c2hs, and cpphs with apt-get. But was unable to find a deb repository for greencard, the final requirement with apt-cache search. I then downloaded the latest version of greencard wget http://www.haskell.org/greencard/downloads/greencard-latest-src.tar.gz and ran sudo make install install-pkg It chugged along for a while, but finally errored out with ghc -package-name greencard -cpp -fglasgow-exts -fno-prune-tydecls -prof -c Foreign/GreenCard.hs -o Foreign/GreenCard.p_o -hisuf p_hi ghc-6.4.1: unrecognised flags: -fno-prune-tydecls I then googled, but found nothing for no-prune-tydecls or no-prune-typedecls (thinking it might be a typo) Anybody out there can help me get greencard working, so I (and all us perlers) can start using PCRE from haskell? thomas. Chris wrote:
I think if you paste the subRegex code above underneath an "import Text.Posix.PCRE" declaration then you get what you are looking for.
To install:
The regex-* package hosting is via darcs and has been copied/moved to
http://darcs.haskell.org/packages/ (The stable regex-* versions) http://darcs.haskell.org/packages/regex-unstable/ (The unstable regex-* vers\ ions)
so "darcs get --partial http://darcs.haskell.org/packages/regex-pcre" might b\ e useful.
They have (hopefully working) cabal files to make compiling and installing ea\ sy. Note that regex-pcre and regex-tre need libpcre and libtre to be installed separately. regex-posix needs a posix library, but GHC already provides this package with a working libary.
-- View this message in context: http://www.nabble.com/trivial-function-application-question-tf2922232.html#a... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

tphyahoo wrote:
Very, very helpful Chris; thanks; and thanks also to the many other helpful haskellers.
They have (hopefully working) cabal files to make compiling and installing ea\ sy.
Unfortunately, not so easy, for PCRE.regex. But hopefully this is just due to my ignorance and there's a simple workaround.
I think that it is simpler than you think. Cabal is confusing you.
At any rate, after darcs --getting as you suggested, I ran make, and got various complaints. I installed haddock, happy, alex, hat, c2hs, and cpphs with apt-get.
Well, the Makefile is just sugar for the Cabal Setup.hs file. Running --configure notices that many things are not installed, but this is just noise from Cabal. With my development directory I get this output from "./setup --configure":
Configuring regex-pcre-0.80... configure: /usr/local/bin/ghc-pkg configure: Dependency base>=2.0: using base-2.0 configure: Dependency regex-base-any: using regex-base-0.71 configure: Using install prefix: /usr/local configure: Binaries installed in: /usr/local/bin configure: Libraries installed in: /usr/local/lib/regex-pcre-0.80/ghc-6.6 configure: Private binaries installed in: /usr/local/libexec configure: Data files installed in: /usr/local/share/regex-pcre-0.80 configure: Using compiler: /usr/local/bin/ghc configure: Compiler flavor: GHC configure: Compiler version: 6.6 configure: Using package tool: /usr/local/bin/ghc-pkg configure: Using ar found on system at: /usr/bin/ar configure: Using haddock found on system at: /usr/local/bin/haddock configure: No pfesetup found configure: Using ranlib found on system at: /usr/bin/ranlib configure: Using runghc found on system at: /usr/local/bin/runghc configure: No runhugs found configure: No happy found configure: No alex found configure: Using hsc2hs: /usr/local/bin/hsc2hs configure: No c2hs found configure: No cpphs found configure: No greencard found
This is sufficient to compile regex-pcre so long as you also have libpcre where ghc will find it. The main this is that it found ghc-6.6 and the hsc2hs and ghc-pkg that came with ghc. Specifically commands to run: make setup # this means Setup.hs is compiled once into "setup" for speed ./setup --configure -p --user --prefix=/where/you/want/it ./setup build ./setup install --user ./setup clean If you really want it to be global, then remove the --user and --prefix and install with sudo. Also, "./setup --help" is useful.

On 06/01/07, Chris Kuklewicz
Running --configure notices that many things are not installed, but this is just noise from Cabal.
This is the second time I've seen someone get confused by these messages. I propose we add a 'Configuration successful, now type runhaskell Setup.hs build.' to the bottom of the configure output. -- -David House, dmhouse@gmail.com

dmhouse:
On 06/01/07, Chris Kuklewicz
wrote: Running --configure notices that many things are not installed, but this is just noise from Cabal.
This is the second time I've seen someone get confused by these messages. I propose we add a 'Configuration successful, now type runhaskell Setup.hs build.' to the bottom of the configure output.
I agree. This issue is even mentioned here: www.serpentine.com/blog/2007/01/05/getting-started-with-installing-third-party-haskell-packages/ Those new to Cabal always seem to assume things are going badly when "happy not found". We need to address the psychological aspect of Cabal's config process :) -- Don

On Sun, Jan 07, 2007 at 12:44:46PM +1100, Donald Bruce Stewart wrote:
dmhouse:
On 06/01/07, Chris Kuklewicz
wrote: Running --configure notices that many things are not installed, but this is just noise from Cabal.
This is the second time I've seen someone get confused by these messages. I propose we add a 'Configuration successful, now type runhaskell Setup.hs build.' to the bottom of the configure output.
I agree. This issue is even mentioned here:
www.serpentine.com/blog/2007/01/05/getting-started-with-installing-third-party-haskell-packages/
Those new to Cabal always seem to assume things are going badly when "happy not found". We need to address the psychological aspect of Cabal's config process :)
But it's not enough to just say "Ignore any errors above". Some packages really do need happy (or some other tool) to build. Cabal would need to crawl over the source files to see what preprocessors are really needed. (It does that in the build phase, but not configure.) If haddock is absent, you can build and install, but not build documentation.

Em Dom, 2007-01-07 às 02:07 +0000, Ross Paterson escreveu:
On Sun, Jan 07, 2007 at 12:44:46PM +1100, Donald Bruce Stewart wrote:
dmhouse:
On 06/01/07, Chris Kuklewicz
wrote: Running --configure notices that many things are not installed, but this is just noise from Cabal.
This is the second time I've seen someone get confused by these messages. I propose we add a 'Configuration successful, now type runhaskell Setup.hs build.' to the bottom of the configure output.
I agree. This issue is even mentioned here:
www.serpentine.com/blog/2007/01/05/getting-started-with-installing-third-party-haskell-packages/
Those new to Cabal always seem to assume things are going badly when "happy not found". We need to address the psychological aspect of Cabal's config process :)
But it's not enough to just say "Ignore any errors above". Some packages really do need happy (or some other tool) to build. Cabal would need to crawl over the source files to see what preprocessors are really needed. (It does that in the build phase, but not configure.) If haddock is absent, you can build and install, but not build documentation.
Maybe if in the Cabal file was specified what's needed for compiling the package, this would not happen. -- malebria Marco Túlio Gontijo e Silva Correio (MSN): malebria@riseup.net Jabber (GTalk): malebria@jabber.org Telefone: 33346720 Celular: 98116720 Endereço: Rua Paula Cândido, 257/201 Gutierrez 30430-260 Belo Horizonte/MG Brasil

On Sun, 2007-01-07 at 02:07 +0000, Ross Paterson wrote:
On Sun, Jan 07, 2007 at 12:44:46PM +1100, Donald Bruce Stewart wrote:
Those new to Cabal always seem to assume things are going badly when "happy not found". We need to address the psychological aspect of Cabal's config process :)
But it's not enough to just say "Ignore any errors above". Some packages really do need happy (or some other tool) to build. Cabal would need to crawl over the source files to see what preprocessors are really needed.
Yes, this is exactly what Cabal should do. We need to do this to make non-trivial pre-processors work properly anyway. We need to have Cabal do the import chasing and work out which tools will be necessary for the build. Duncan

Ross Paterson wrote:
Cabal would need to crawl over the source files to see what preprocessors are really needed.
Duncan Coutts wrote:
Yes, this is exactly what Cabal should do.
In the meantime, how about the following: In default non-verbose mode, silently memoize the list of packages that were not found. Then, only if something goes wrong, say something like: "The package failed to build. Perhaps the reason is that one of the following packages was not found:" In non-default verbose mode, behave as now. -Yitz

Hi
In the meantime, how about the following:
In default non-verbose mode, silently memoize the list of packages that were not found. Then, only if something goes wrong, say something like:
"The package failed to build. Perhaps the reason is that one of the following packages was not found:"
That doesn't seem that helpful. On error, give a list of maybe 25 things that are missing, only to find out that you're running GHC 6.4.1 on Windows which no one ever tried before. It's not really narrowing the cause of the error too much anyway. Something like scons does this much much better than Cabal does - it only complains if it finds something you need but don't have. For example, with Yhc you can compile the compiler with GHC, and the runtime with GCC/Visual Studio. Lacking half those dependancies won't give you an error message if you only try to do the right thing. Thanks Neil

I wrote:
In the meantime, how about the following:
In default non-verbose mode, silently memoize the list of packages that were not found. Then, only if something goes wrong, say something like:
"The package failed to build. Perhaps the reason is that one of the following packages was not found:"
Neil Mitchell wrote:
That doesn't seem that helpful. On error, give a list of maybe 25 things that are missing, only to find out that you're running GHC 6.4.1 on Windows which no one ever tried before. It's not really narrowing the cause of the error too much anyway.
Oh, I agree completely. Clearly it would be great if Cabal could process and report dependencies in a more meaningful way. However, if that will take more time before it can happen, I am just supporting what a few other people have already suggested in this thread as an easy first step. These do not require any change in the way Cabal processes things - just the way messages are printed. I am just combining a few things already said : o Verbose and non-verbose options. o Always show information if something really went wrong. o Include a message that may help people not to panic as much. -Yitz

On 07/01/07, Ross Paterson
But it's not enough to just say "Ignore any errors above". Some packages really do need happy (or some other tool) to build. Cabal would need to crawl over the source files to see what preprocessors are really needed.
Even if we said something like the following would be better: 'runhaskell Setup.hs build' to continue. The tools listed above as 'not found' may be required by the package; the build process will tell you if this is the case. We need _something_ there. More complex solutions will likely have their advantages, but _some_ solution is needed. -- -David House, dmhouse@gmail.com

Donald Bruce Stewart writes:
dmhouse:
This is the second time I've seen someone get confused by these messages. I propose we add a 'Configuration successful, now type runhaskell Setup.hs build.' to the bottom of the configure output.
I agree. This issue is even mentioned here:
www.serpentine.com/blog/2007/01/05/getting-started-with-installing-third -party-haskell-packages/
Those new to Cabal always seem to assume things are going badly when "happy not found". We need to address the psychological aspect of Cabal's config process :)
Perhaps it would be better not to print the missing component messages
by default. There could be a verbose option to turn them back on.
--
David Menendez

tphyahoo:
So the core question (speaking as a perler) is how do you write
my $s= 'abcdefg'; $s =~ s/a/z/g; $s =~ s/b/y/g; print "$s\n";
Simple patterns like this you'd just use a 'map' of course: main = print (clean "abcdefg") clean = map (by . az) where by c = if c == 'b' then 'y' else c az c = if c == 'a' then 'z' else c Running this: $ runhaskell A.hs "zycdefg" Now, using regexes instead we can get by with just the regex-compat lib, providing: import Text.Regex I usually flip the arguments to subRegex, since they're in the wrong order for composition (anyone else noticed this?): sub re y s = subRegex re s y regex = mkRegex Now , using proper regexes, we can write: main = print (clean "abcdefg") clean = sub (regex "b") "y" . sub (regex "a") "z" Running this: $ runhaskell A.hs "zycdefg" Similar results will be achieved with the other regex-* packages: http://haskell.org/haskellwiki/Libraries_and_tools/Compiler_tools#Regular_ex... I think TRE might be preferred for high performance cases. -- Don
participants (15)
-
Bill Wood
-
brad clawsie
-
Brandon S. Allbery KF8NH
-
Chris Kuklewicz
-
David House
-
David Menendez
-
dons@cse.unsw.edu.au
-
Duncan Coutts
-
J. Garrett Morris
-
Jules Bean
-
Marco Túlio Gontijo e Silva
-
Neil Mitchell
-
Ross Paterson
-
tphyahoo
-
Yitzchak Gale