Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: flatten comma operator (Brent Yorgey)
2. Re: flatten comma operator (Arlen Cuss)
3. Re: wrapping text in a multiline string (Arlen Cuss)
4. Re: wxHaskell path (Henry Lockyer)
5. Re: wxHaskell install errors (Heinrich Apfelmus)
6. Re: histogram over large data (Ben Gamari)
----------------------------------------------------------------------
Message: 1
Date: Wed, 6 Jun 2012 06:58:57 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] flatten comma operator
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Jun 06, 2012 at 09:46:58AM +0200, Kees Bleijenberg wrote:
> This is indeed the code I was talking about.
> I did not understand how I could create (1,2,3) with the comma operator
> (,)((,) 1 2) 3 = ((1,2),3) and not (1,2,3). That's why I thought I needed a
> kind of join operation to 'flatten' this.
It's not possible to create a triple using only the (,) operator --
there's no way to do the join/flatten operation you have in mind,
because there's no valid type it could be assigned (unless you make it
specific to three-tuples, but I'm guessing you have something more
general in mind).
> Indeed (,,) 1 2 3 is (1,2,3). But I do not understand what is happening. Is
> (,,) predefined? Probably not.
Yes, it is!
-Brent
------------------------------
Message: 2
Date: Wed, 6 Jun 2012 21:06:04 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] flatten comma operator
To: Kees Bleijenberg <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Wednesday, 6 June 2012 at 5:46 PM, Kees Bleijenberg wrote:
> This is indeed the code I was talking about.
> I did not understand how I could create (1,2,3) with the comma operator
> (,)((,) 1 2) 3 = ((1,2),3) and not (1,2,3). That's why I thought I needed a
> kind of join operation to 'flatten' this.
As Brent pointed out, you can't without making it very specific. Each length of
tuple with its combination of types is a unique type itself; compare to a list,
where [a] is the type for a list of any length (including zero) containing
elements of type a. A list is trivial to append to, whereas tuples are not
designed for "extension" in this manner, per se.
> Indeed (,,) 1 2 3 is (1,2,3). But I do not understand what is happening. Is
> (,,) predefined? Probably not.
And as Brent pointed out also, it is. :) By the way, so is
(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)!
I suspect GHC allows any number. The Haskell Report section 6.1.4 [1] says
implementations must support up to at least 15.
Cheers,
Arlen
[1] http://www.haskell.org/onlinereport/basic.html
>
>
> -----Oorspronkelijk bericht-----
> Van: Arlen Cuss [mailto:[email protected]]
> Verzonden: woensdag 6 juni 2012 8:43
> Aan: Kees Bleijenberg
> CC: [email protected] (mailto:[email protected])
> Onderwerp: Re: [Haskell-beginners] flatten comma operator
>
> By the way, is the excerpt from RWH involving liftA2 the chapter on using
> Parsec? If so, this may be the code snippet you refer to:
>
> -- file: ch16/FormApp.hs a_pair :: CharParser () (String, Maybe String)
> a_pair = liftA2 (,) (many1 a_char) (optionMaybe (char '=' *> many a_char))
>
> In this case, liftA2 is promoting the (,) operation to work with the two
> operations in the CharParser applicative functor.
>
> (,) is of type "a -> b -> (a,b)", so without lifting, we'd end up with
> something like "(CharParser () String, CharParser () Maybe String)" (just a
> guess here).
>
> liftA2 produces a new applicative functor action which computes each of
> (many1 a_char) and (optionMaybe (char '=' *> many a_char)), then gives the
> pure results to (,).
>
>
> On Wednesday, 6 June 2012 at 4:36 PM, Arlen Cuss wrote:
>
> > If (,) is a function that takes two elements and returns the 2-tuple,
> > have you considered something like (,,)? :)
> >
> >
> >
> > On Wednesday, 6 June 2012 at 4:33 PM, Kees Bleijenberg wrote:
> >
> > > In 'Real World Haskell' I found code like LiftA2 (,) ....
> > > Looks odd. But after some experimenting in winghci I found that (,) 1 2
> >
>
>
> is valid code and is equal to (1,2).
> > > Now I wonder how to create (1,2,3). I think you need a join or a flatten
> >
>
>
> function or ...? Join doesn't work?
> > >
> > > Kees
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected] (mailto:[email protected])
> > > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected] (mailto:[email protected])
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Wed, 6 Jun 2012 21:25:44 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] wrapping text in a multiline string
To: Rico Moorman <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Since I can't seem to get the PCRE package installed (not sure what's going on
here: http://hpaste.org/69589), I gave it a go with plain Text.Regex, which
should (?) use Text.Regex.Posix by default.
?> let regex = mkRegexWithOpts "abc(.*)def" False False in matchRegex regex
"abc content\nmore def"
Just [" content\nmore "]
?>
See:
http://hackage.haskell.org/packages/archive/regex-compat/0.92/doc/html/Text-Regex.html#v:mkRegexWithOpts
That said, Text.Regex.Posix is a bit broken, and you might want to use
regex-tdfa. See also:
* http://www.haskell.org/haskellwiki/Regex_Posix
* http://www.haskell.org/haskellwiki/Regular_expressions
Cheers,
A
On Wednesday, 6 June 2012 at 6:39 PM, Rico Moorman wrote:
> Thank you again!
>
> Looking at the docs it seems that this could do the trick. A pity that
> you cannot install the package.
>
> Now I am wondering how I would integrate this in the replacement
> function or how to rewrite it properly.
>
> Looking at the type signature of =~~ (with my limited knowledge) it
> seems that I would have to "use" RegexMaker adding up the CompOptions
> needed?
>
> (=~~) :: (RegexMaker Regex CompOption ExecOption source, RegexContext
> Regex source1 target, Monad m) => source1 -> source -> m target
>
>
> On Wed, Jun 6, 2012 at 9:46 AM, Arlen Cuss <[email protected]
> (mailto:[email protected])> wrote:
> >
> > Exploring the documentation for Text.Regex.PCRE, I've found "CompOption":
> >
> > http://hackage.haskell.org/packages/archive/regex-pcre/0.94.4/doc/html/Text-Regex-PCRE-Wrap.html#t:CompOption
> >
> > The constants are listed below; the one you want is probably compDotAll, to
> > make "." match newlines as well. I'm not 100% sure if this is the module
> > you want, though, and I can't seem to get regex-pcre installed, so I can't
> > test. Apologies!
> >
> >
> > On Wednesday, 6 June 2012 at 4:52 PM, Rico Moorman wrote:
> >
> > > Thank you very much for this suggestion. I just tried the character class
> > > you mentioned and it works.
> > >
> > > The stackoverflow post you mentioned was a nice read and I surely agree
> > > that regular expressions are normally not the way to go for most HTML
> > > munging needs. But luckily the generated HTML from pandoc is very
> > > specific and the <table> tag I wanted to match (for line-numbered code
> > > listings) does not contain any further tables so I thought it should be
> > > safe to approach it like this.
> > >
> > > The resulting code is now:
> > >
> > > -- Wraps numbered code listings within the page body with a div
> > > -- in order to be able to apply some more specific styling.
> > > wrapNumberedCodelistings (Page meta body) =
> > > Page meta newBody
> > > where
> > > newBody = regexReplace
> > > "<table\\s+class=\"sourceCode[^>]+>[\\s\\S]*?</table>" wrap body
> > > wrap x = "<div class=\"sourceCodeWrap\">" ++ x ++ "</div>"
> > >
> > > -- Replaces the whole match for the given regex using the given function
> > > regexReplace :: String -> (String -> String) -> String -> String
> > > regexReplace regex replace text = go text
> > > where
> > > go text = case text =~~ regex of
> > > Just (before, match, after) ->
> > > before ++ replace match ++ go after
> > > _ -> text
> > >
> > >
> > > Don't know though if it could be cleaned up further or even if this is by
> > > any means good style (being still fairly new to haskell).
> > >
> > > Furthermore I would still be very interested in the right approach to
> > > manipulating the HTML structure as a whole and I too hope that another
> > > Haskeller could name a more suitable solution for manipulating HTML.
> > > Or even how to pass the 's' modifier to Text.Regex.PCRE.
> > >
> > > Best regards,
> > >
> > > rico
> > >
> > > On Wed, Jun 6, 2012 at 7:11 AM, Arlen Cuss <[email protected]
> > > (mailto:[email protected])> wrote:
> > > > I'd be more inclined to look at a solution involving manipulating the
> > > > HTML structure, rather than trying a regexp-based approach, which will
> > > > probably end up disappointing. (See this:
> > > > http://stackoverflow.com/a/1732454/499609)
> > > >
> > > > I hope another Haskeller can speak to a library that would be good for
> > > > this kind of purpose.
> > > >
> > > > To suit what you're doing now, though; if you change .*? to [\s\S]*?,
> > > > it should work on multiline strings. If you can work out how to pass
> > > > the 's' modifier to Text.Regexp.PCRE, that should also do it.
> > > >
> > > > ?Arlen
> > > >
> > > >
> > > > On Wednesday, 6 June 2012 at 3:05 PM, Rico Moorman wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I have a given piece of multiline HTML (which is generated using
> > > > > pandoc btw.) and I am trying to wrap certain elements (tags with a
> > > > > given class) with a <div>.
> > > > >
> > > > > I already took a look at the Text.Regex.PCRE module which seemed a
> > > > > reasonable choice because I am already familiar with similar regex
> > > > > implementations in other languages.
> > > > >
> > > > > I came up with the following function which takes a regex and
> > > > > replaces all matches within the given string using the provided
> > > > > function (which I would use to wrap the element)
> > > > >
> > > > > import Text.Regex.PCRE ((=~~))
> > > > >
> > > > > -- Replaces the whole match for the given regex using the given
> > > > > function
> > > > > regexReplace :: String -> (String -> String) -> String -> String
> > > > > regexReplace regex replace text = go text
> > > > > where
> > > > > go text = case text =~~ regex of
> > > > > Just (before, match, after) ->
> > > > > before ++ replace match ++ go after
> > > > > _ -> text
> > > > >
> > > > > The problem with this function is, that it will not work on multiline
> > > > > strings. I would like to call it like this:
> > > > >
> > > > > newBody = regexReplace "<table class=\"sourceCode\".*?table>" wrap
> > > > > body
> > > > > wrap x = "<div class=\"sourceCodeWrap\">" ++ x ++ "</div>"
> > > > >
> > > > > Is there any way to easily pass some kind of multiline modifier to
> > > > > the regex in question?
> > > > >
> > > > > Or is this approach completely off and would something else be more
> > > > > appropriate/haskelly for the problem at hand?
> > > > >
> > > > > Thank you very much in advance.
> > > > > _______________________________________________
> > > > > Beginners mailing list
> > > > > [email protected] (mailto:[email protected])
> > > > > (mailto:[email protected])
> > > > > http://www.haskell.org/mailman/listinfo/beginners
> > > >
> > >
> >
>
------------------------------
Message: 4
Date: Wed, 6 Jun 2012 12:31:16 +0100
From: Henry Lockyer <[email protected]>
Subject: Re: [Haskell-beginners] wxHaskell path
To: Miguel Negrao <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
Thanks a lot Miguel. I recently discovered your posts about 'reactive banana'
and wxHaskell and started looking through them.
Unfortunately I am a c/c++ compilation/make/etc. and general unix newbie, or
oldbie in my case, (amongst many other areas of deep ignorance ;-)
so I am finding some of the information/instructions a little hard to follow.
I went for version 2.9 of widgets first, as it seemed better, for the reasons
you mention.
In fact the wxHAskell mac-specific advice only refers to 2.9, on the page you
refer to.
I downloaded 2.9.3 from wxWidgets.org as I'm not familiar with homebrew.
I followed the wxWidgets installation instructions to build it. Which mostly
seemed to be OK but with a warning about QuickTime
which is evidently a 32 vs 64 bit issue.
I tried to make sure everything was OK at each step before going on to the next
one, to avoid Too Many Variables syndrome,
so before installing wxHaskell I checked out wxWidgets 2.9.3 with some of the
demos. Some of them did not seem
to be working quite right, also I had questions about the path variable,
removing the 2.8.8 libraries, 32 vs 64 bit, QuickTime etc.
and started thinking it might be more efficient to just go with the existing
2.8.8 widgets in the meantime, but then immediately
hit the $wxwin question !
I did wonder if $wxwin might be specific to Windows, but on the wxHaskell page
I linked below it is in the main flow of the
text rather than in the Windows/MacOSX-specific parts.
I posted my earlier questions on the "wxhaskell-users" list but it seems a bit
quiet there so I might re-post them here.
How did you establish that your wxWidgets was installed and working as
expected,
and can I ask how you removed the pre-loaded mac os version of widgets (if you
had this) ?
Regards/ Henry
On 6 Jun 2012, at 09:04, Miguel Negrao wrote:
>
> A 06/06/2012, ?s 00:39, Henry Lockyer escreveu:
>
>> Hi all
>> Trying to work out how to get wxHaskell correctly installed on mac os x
>> (10.6.8 snow leopard).
>> Have decided to try and get the older version working (0.13) so as to use
>> the pre-installed
>> wxWidgets (2.8.8 it seems). I was looking at the wxHAskell install info for
>> mac os x at
>> (1) http://www.haskell.org/haskellwiki/WxHaskell/MacOS_X - which only
>> talks about widgets 2.9,
>> but I have now been reading
>> (2) http://www.haskell.org/haskellwiki/WxHaskell/2.8
>>
>> Question:
>> The variable "$wxwin" is referred to in the page at link (2) above, where it
>> says:
>> "We assume in this guide that the variable $wxwin points to your wxWidgets
>> installation directory, for example: ~/dev/wxGTK-2.8.10."
>> And in the page at link (1), step 3, it says:
>> "Check your path to make sure you are using your wxWidgets and not the
>> default Mac one"
>>
>> Are these referring to the same thing? ( I had originally interpreted
>> 'path' as referring to $PATH.)
>>
>> The reference to $wxwin is in instructions for building wxWidgets 2.8 which
>> I should not need to do if I am
>> using the already installed 2.8.8 widgets library, but if I echo $wxwin it
>> is blank and does not therefore appear to
>> point to my wxWidgets installation directory.
>> Is this an issue or is it only relevant to the initial build process for
>> wxWidgets?
>>
>> Can anyone throw any light on this?
>
> Not exactly what you are asking for but I recently installed wxHaskell latest
> version with wxWidgets 2.9 on osx 10.7.3 successfully using the instructions
> here http://www.haskell.org/haskellwiki/WxHaskell/MacOS_X and some help from
> the list.
>
> I installed wxWidgets from homebrew (http://mxcl.github.com/homebrew/) which
> is very easy to do, a one liner. I think the 2.9 version is much better for
> osx, it has 64 bit support and uses cocoa:
>
> "2.9 series bring many improvements compared to 2.8 series such as much
> better and simpler to use support for Unicode and the new wxOSX/Cocoa port,
> suitable for development of 64 bit GUI applications under OS X, as well as a
> huge number of other new features and bug fixes."
>
> It should be something like:
>
> brew install wxmac --devel
>
> then
>
> cabal install wx cabal-macosx
>
> or if have issues with the command above install the correct versions of the
> dependencies in the right order by hand:
>
> cabal install wxdirect-0.90.0.1
> cabal install wxc-0.90.0.3
> cabal install wxcore-0.90.0.1
> cabal install wx-0.90.0.1
> cabal install cabal-macosx
>
> When I did this I got it working inside EclipseFP although I couldn?t get ghc
> to compile a hello world program, which I guess means I should be passing it
> some flag that I don?t know about.
>
> Hope this helps,
> Miguel Negr?o
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Wed, 06 Jun 2012 16:20:13 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: Re: [Haskell-beginners] wxHaskell install errors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Gregory Guthrie wrote:
> I had all of the wxHaskell programs installed and working fine, but now with
> an update to Haskell Platform and thus also ghci, I need to upgrade all of
> them (the previously working programs fail) requiring an update for the
> underlying wxWidgets from 2.8 to 2.9 versions.
>
> I downloaded and built wxWidgets 2.9, since the current wxHaskell
> libraries require it (I couldn't find any existing binaries online).
> The compile seemed to be successful, but when I then try to use it
> from the wxHaskell programs I get an error that I don't know how to fix:
>
> C: >cabal install wx
> Resolving dependencies...
> [1 of 1] Compiling Main (
> C:\Users\guthrie\AppData\Local\Temp\wxc-0.
> 90.0.3-7324\wxc-0.90.0.3\Setup.hs,
> C:\Users\guthrie\AppData\Local\Temp\wxc-0.90.
> 0.3-7324\wxc-0.90.0.3\dist\setup\Main.o ) Linking
> C:\Users\guthrie\AppData\Local\Temp\wxc-0.90.0.3-7324\wxc-0.90.0.3\dist\
> setup\setup.exe ...
> Configuring wxc-0.90.0.3...
> Configuring wxc to build against wxWidgets 2.9
>
> setup.exe: Missing dependencies on foreign libraries:
> * Missing C libraries: wxmsw29ud_all, wxtiffd, wxjpegd, wxpngd,
> wxzlibd,wxregexud, wxexpatd, wxregexud This problem can usually be solved by
> installing the system packages that provide these libraries (you may need the
> "-dev" versions). If the libraries are already installed but in a
> non-standard location then you can use the flags --extra-include-dirs= and
> --extra-lib-dirs= to specify where they are.
> cabal: Error: some packages failed to install:
> wx-0.90.0.1 depends on wxc-0.90.0.3 which failed to install.
> wxc-0.90.0.3 failed during the configure step. The exception was: ExitFailure
> 1
> wxcore-0.90.0.1 depends on wxc-0.90.0.3 which failed to install.
Are you sure that you installed wxWidgets 2.9 and didn't just compile it
from source? It looks like cabal can't find the wxWidgets libraries on
your system.
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 6
Date: Wed, 06 Jun 2012 15:54:08 +0100
From: Ben Gamari <[email protected]>
Subject: Re: [Haskell-beginners] histogram over large data
To: [email protected]
Cc: Ian Knopke <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Ian Knopke <[email protected]> writes:
> Hi,
>
> I'd like to build a histogram, or even just a frequency count of some
> categorical data from a large database. In a language such as perl I'd
> do something like this:
>
> my %freq; # hash
> while (my $item = get_next_from_db()){
> $freq{$item}++;
> }
>
> and then sum the hash values and divide the value of each key by the
> sum to get the histogram.
>
> Is there an easy way to do the same thing in Haskell? It looked like
> an easy task but I seem to be having a lot of trouble getting this to
> work properly, as it doesn't seem to be behaving very lazily. I'm
> guessing I should be doing something with the State monad, but I'm not
> very good at using that yet.
>
I have a package[1] which I'll eventually put up on Hackage for plotting
histograms with Chart[2]. The underlying histogram implementation (for
homogenous bin widths only) is intended for use with dense data and
internally keeps its accumulator in a mutable vector in the ST
monad. Feel free to borrow the code
(chart-histogram/Numeric/Histogram.hs).
Cheers,
- Ben
[1] https://github.com/bgamari/chart-histogram
[2] http://hackage.haskell.org/package/Chart
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 48, Issue 9
****************************************