[Haskell-cafe] Re: Problem getting code from AFP08 parallel tutorial to run in parallel

2008-11-27 Thread Olivier Boudry
On Tue, Nov 25, 2008 at 11:07 PM, Don Stewart [EMAIL PROTECTED] wrote:
 What does the code look like?

It looks like that. Of course it doesn't compute the same number as
the initial code, but it starts 3 sparks and I get the expected 100%
CPU usage instead of 50%.

parSumFibEuler :: Int - Int - Int - Int
parSumFibEuler a b c
  = f `par` (e `par` (g `pseq` (f + e + g)))
where
  f = fib a
  e = sumEuler b
  g = sumEuler c

r1 :: Int
r1 = parSumFibEuler 40 7450 7449

Instead of:

parSumFibEuler :: Int - Int - Int
parSumFibEuler a b
  = f `par` (e `pseq` (f + e))
where
  f = fib a
  e = sumEuler b

r1 :: Int
r1 = parSumFibEuler 40 7450

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Problem getting code from AFP08 parallel tutorial to run in parallel

2008-11-25 Thread Olivier Boudry
On Tue, Nov 25, 2008 at 3:07 PM, Simon Marlow [EMAIL PROTECTED] wrote:
 Yes, it's a scheduling bug.  I'll make sure it gets fixed for 6.10.2.  If
 you have more sparks then you shouldn't see this problem.  Also, GHC HEAD is
 quite a lot better with parallel programs than 6.10.1, I'll try to get
 around to posting some figures sometime.

Yes, I tried it with 3 sparks and it works,

Thanks for your help,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problem getting code from AFP08 parallel tutorial to run in parallel

2008-11-24 Thread Olivier Boudry
Hi all,

I'm reading the following tutorial:
http://research.microsoft.com/~simonpj/papers/parallel/AFP08-notes.pdf
A Tutorial on Parallel and Concurrent
Programming in Haskell and have problems getting the expected speed
improvement from running two tasks in parallel. With any version of
the code present in pages 1-7 of the tutorial I keep getting the CPU
stick to 50%.

I did not forget to compile the code with `-threaded` and run it with
`+RTS -N2` and it runs on a dual core machine on which I already used
the Control.Parallel.Strategies.parMap function and got 100% CPU
usage.

The first version of the parallel function in the tutorial (page 6) is:

parSumFibEuler :: Int − Int − Int
parSumFibEuler a b
  = f 'par' (f + e)
  where
f = fib a
e = sumEuler b

In the tutorial, swapping f and e on the 3rd line does the job, but in
my case it doesn't change anything.

C:\Temp\haskellghc --make -threaded SumEulerP6.hs
[1 of 1] Compiling Main ( SumEulerP6.hs, SumEulerP6.o )
Linking SumEulerP6.exe ...

C:\Temp\haskellSumEulerP6 +RTS -N1
sum: 119201850
time: 36.890625 seconds

C:\Temp\haskellSumEulerP6 +RTS -N2
sum: 119201850
time: 36.859375 seconds

Next page of the tutorial the tasks are explicitly sequenced so the
code does not depend on the ordering of the two `+` operands:

parSumFibEuler :: Int - Int - Int
parSumFibEuler a b
  = f `par` (e `pseq` (f + e))
where
  f = fib a
  e = sumEuler b

With once again a disappointing result:

C:\Temp\haskellghc --make -threaded SumEulerP7.hs
[1 of 1] Compiling Main ( SumEulerP7.hs, SumEulerP7.o )
Linking SumEulerP7.exe ...

C:\Temp\haskellSumEulerP7 +RTS -N1
sum: 119201850
time: 36.875 seconds

C:\Temp\haskellSumEulerP7 +RTS -N2
sum: 119201850
time: 36.75 seconds

I tried this on a Windows XP Dell Dual Core with GHC 6.10.1 and on a
iMac Dual Core with GHC 6.8.3 and got the same result on both. I'm
probably missing something really stupid but I'm lacking the parallel
thinking skills to understand how to look at the problem and resolve
it.

Any pointers?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ActiveX and COM

2008-08-04 Thread Olivier Boudry
On Mon, Aug 4, 2008 at 2:14 PM, Fernand [EMAIL PROTECTED] wrote:
 If you need to simply create and Excel Sheet, you may also try it using the
 new Microsoft XML format (it will only work with Office 2007, though) ; then
 you do not need COM.

 Sincerely yours,

 Fernand

Hi Fernand and Günther,

A few month ago I wrote some haskell to parse an XML document and
create an Excel XML document from the data. I just pasted the code
here: http://hpaste.org/9381

I'm using Excel 2003 and it works with XML.

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ActiveX and COM

2008-08-04 Thread Olivier Boudry
Ooops, I just realized that hpaste truncated my source file at 5k
(it's 8k long). Unfortunately the Excel file creation code is in the
truncated part of the file ;-)

So if you are interested in getting the full source, just ask.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linker problems linking FFI import call in Windows

2008-07-17 Thread Olivier Boudry
On Wed, Jul 16, 2008 at 6:22 PM, PJ Durai [EMAIL PROTECTED] wrote:
 I do have the import library. It came with the DLL. It links properly
 when I use CCALL on the haskell import statements. Doesnt link when I
 use STDCALL. It looks for  function name with something like '@4 or
 @8' tacked on at the end. Not sure what that is all about.

Is your import library a .lib or a .a file? If you have a .lib
import library ghc will ignore it and link directly with the DLL.

I think you can convert a .lib to a .a using the reimp tool which
is part of the mingw utilities.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linker problems linking FFI import call in Windows

2008-07-16 Thread Olivier Boudry
On Tue, Jul 15, 2008 at 11:51 PM, PJ Durai [EMAIL PROTECTED] wrote:
 I am trying to import some functions from a windows DLL. I am getting
 strange errors. (This used to work with previous versions of GHC.  6.6
 I think.).

You may have to create an import library for the DLL. I had a similar
problem and solved it that way.

Look at http://www.emmestech.com/moron_guides/moron1.html for advices
on how to create such a library.

My problem was that the exports in the dll were prefixed with an
underscore. I had to remove them from the .def file before creating
the import library.

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANNOUNCE: hfann-01

2008-06-09 Thread Olivier Boudry
Hi all,

I'm pleased to announce the first release of the hfann module (
http://code.haskell.org/~oboudry/hfann/). This module is an interface to the
Fast Artificial Neural Network (FANN) library (see
http://leenissen.dk/fann/).

This is an early release. At the moment the hfann module does not cover all
the functions found in the FANN library but it should be useable to train
and use simple Neural Networks. At least is can be used to run an equivalent
of the Getting Started example found in
http://leenissen.dk/fann/html/files2/gettingstarted-txt.html.

The module was developped on Windows XP with GHC-6.8.2.

The README should provide you with all required information to install this
module. The haddock documentation should give enough information to get
started using it.

== Installation ==

Download version 2.0 of the FANN library from:

http://leenissen.dk/fann/download.php

and build it according to the instruction found on:

http://leenissen.dk/fann/html/files2/installation-txt.html

Get the hfann module

darcs get http://code.haskell.org/~oboudry/hfann/

Build it using Cabal

runghc Setup.lhs configure
runghc Setup.lhs build
runghc Setup.lhs haddock
runghc Setup.lhs install

== Examples ==

Training an ANN to the xor function:

 import HFANN

 main = do
   withStandardFann [2,3,1] $ \fann - do
 setActivationFunctionHidden fann fannSigmoidSymetric
 setActivationFunctionOutput fann fannSigmoidSymetric

 trainOnFile fann xor.data -- train data
  2  -- max epochs
  100-- epochs between reports
  0.001  -- desired error

 saveFann fann xor.ann

C:\Temp\Haskell\hfann\examples\xorTrain.exe
Max epochs2. Desired error: 0.001000.
Epochs1. Current error: 0.2503675520. Bit fail 4.
Epochs  100. Current error: 0.0181358512. Bit fail 0.
Epochs  169. Current error: 0.0009599295. Bit fail 0.


Using the trained ANN on the 4 possible input values to the xor function (-1
= False, 1 = True).

 import HFANN

 main = do
   withSavedFann xor.ann $ \fann - do
 mapM_ (\x - runFann fann x = print) [[-1,-1],[-1,1],[1,-1],[1,1]]

C:\Temp\Haskell\hfann\examples\xorUse.exe
[-0.950566361876292]
[0.9178714756661263]
[0.9457588340834527]
[-0.9482816646878051]

The xor.data training data content:
4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
-1

The files for this example can be found in the examples/xor directory

==

Bug reports, suggestions and comments are welcome. You can send them
directly to my e-mail address.

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: hfann-01

2008-06-09 Thread Olivier Boudry
On Mon, Jun 9, 2008 at 11:29 AM, Don Stewart [EMAIL PROTECTED] wrote:

 Excellent. Would you like to upload it to hackage.haskell.org, so it can
 be easily installed with the 'cabal install' tool?


Hi all,

As suggested by Don, I just uploaded the hfann package to
hackage.haskell.org.

It's available here:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hfann

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Question on type synonym definition and language extensions

2008-05-29 Thread Olivier Boudry
Hi all,

I'm trying to define a type synonym for 2D MArray instances. The goal is to
keep the function signature simple and readable using type `Matrix` instead
of something like `(Ix i, MArray a e m) = m (a i e)`.

After some read, guess, try, error cycles I came up with this:

type Matrix = forall m. forall a. forall i. forall n. (Ix i, MArray a n
m, Num i, Num n) = m (a (i,i) n)

it requires option -XRank2Types to work. But then I can write my function
as:

test :: Matrix
test = do { a - newArray ((0,0),(5,8)) 0; writeArray a (0,0) 1; return
a }

Then I wanted to be able to give the Index and Value types in the type
synonym but keep it flexible in terms of which MArray instance is used. I
changed it to:

type Matrix i n = forall m. forall a. (MArray a n m) = m (a (i,i) n)

and the type signature of the test function becomes:

test :: Matrix Int Double

For this one I had to add an extra -XFlexibleContexts option to build it.

It works and I'm quite happy with the look of my new function type
signatures, but I'm just wondering if I'm doing something bad or if there is
a cleaner/simpler way to define the same type synonym without requiring
language extensions. What are the risks associated with using these two
language extensions, non compatibility with other compilers or more?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Question on type synonym definition and language extensions

2008-05-29 Thread Olivier Boudry
On Thu, May 29, 2008 at 4:38 PM, Henning Thielemann 
[EMAIL PROTECTED] wrote:

 Is

  type Matrix monad array num = monad (array (Int,Int) num)

 ok for you?


Not really what I was looking for but I may end up using it.

What I wanted is to hide the Monad and Array and have it inferred from the
context of the array

STArray or STUArray when run in the ST monad with runST(U)Array, IOArray or
IOUArray when used in the IO monad, etc...

I'm not sure it's the right thing to do. I may create more troubles than I
solve. I was just trying to keep things as generic as possible.

Thanks for your reply,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Question on type synonym definition and language extensions

2008-05-29 Thread Olivier Boudry
On Thu, May 29, 2008 at 7:36 PM, Antoine Latter [EMAIL PROTECTED] wrote:

 I've tried similar things before.  You may run into subtle problems later.

 Such as:

  transpose :: Matrix - Matrix

 won't expand into the type signature you want it to, I think.

 You probably want that to be equivalent to:

 transpose ::  forall m. forall a. forall i. forall n. (Ix i, MArray a
 n m, Num i, Num n) = m (a (i,i) n) - m (a (i,i) n)

 But you'll get:

 transpose ::  forall m. forall a. forall i. forall n. (Ix i, MArray a
 n m, Num i, Num n) = Matrix - m (a (i,i) n)

 which means that the first argument must be a polymorphic value, which
 isn't very useful.


Right, this is exactly what I'm getting when creating a transpose function:

*Main :t transpose
transpose :: (MArray a Double m) = Matrix Int Double - m (a (Int, Int)
Double)

Thanks for sharing your experience. I'll try to stay out of the subtle bugs
and keep it verbose but simple.

Regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] Newbie: State monad example questions

2008-05-24 Thread Olivier Boudry
On Sat, May 24, 2008 at 3:39 AM, Bulat Ziganshin [EMAIL PROTECTED]
wrote:

 Hello Olivier,

 Saturday, May 24, 2008, 5:37:32 AM, you wrote:

 (|) = flip (.)

  I even started to use it in my code and then stopped. It may be a
  stupid concern but as many optimizations performed by GHC are made
  through rewrite rules and I was worried that those rules may not
  fire when using this new operator.

 afaik ghc, | would be rewritten to flip (.) which would be rewritten
 to application of first function to second one and so on. rewrite
 rules doesn't work only on your original code but on intermediate
 variations too

 That's really good news.

Thanks Bulat,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] library for drawing charts

2008-05-24 Thread Olivier Boudry
On Sat, May 24, 2008 at 5:33 AM, Peter Gammie [EMAIL PROTECTED] wrote:

 Hello,

 Has anyone got some code for drawing charts?


Look at this:
http://byorgey.wordpress.com/2008/04/30/new-haskell-diagrams-library/

I'm not sure it's what you're looking for but it could probably be used as a
base for drawing charts.

Brent Yorgey announced version 0.1 on the list a few weeks ago.

Regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie: State monad example questions

2008-05-23 Thread Olivier Boudry
On Fri, May 23, 2008 at 2:20 PM, Thomas Hartman [EMAIL PROTECTED] wrote:

  The big benefit I got from using the State Monad was that I was able to
 reorder the functions  by just copy/pasting the function name from one
 place to another.

 I don't understand... why do you need state to do this? Couldn't you
 have a function pipeline using dots for composition like

   (
...
parseAttn .
parsePoBox .
...
) address ...

 and have the functions be equally switchable? (well, the first and
 last can't quite be copy pasted, but close enough.)

 Introducing state seems like a lot of trouble to me if the only one is
 easier reorderability of lines.


Agreed, in fact I started with a function pipeline and then switched to
using the State Monad. As the program was written months ago I don't
remember exactly why. Maybe I don't like to read backwards. ;-)

Funtions running in the state monad can call other functions with the same
`State s a` signature (and so on as deep as you want). You never have to
care about passing parameters and restarting a new pipeline. But of course
you can easily do without the State Monad. I don't think the State Monad
allows to do thing that you can't do with basic Haskell. It just makes code
more readable (in my opinion at least).

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie: State monad example questions

2008-05-22 Thread Olivier Boudry
On Wed, May 21, 2008 at 6:19 PM, Dmitri O.Kondratiev [EMAIL PROTECTED]
wrote:


 -- Then we can use  this State object (returned by getAny) in a function
 generating random values such as:

 makeRnd :: StdGen - (Int, StdGen)
 makeRnd = runState (do
   y - getAny
   return y)


You can simplify this:

do y - m
return y

is equivalent to

`do m`

or `m`

According to Monad Laws.

So you could write the same code as:
makeRnd = runState getAny

In that case, the use of the State Monad is not really interesting as you
just replaced a call to `random g` with a call to `runState getAny g`. The
State Monad is interesting if you have more than one action in the first
argument of the `runState` function because the state passing will only work
in a single `State s a`.

Thomas Hartman asked for use cases so I will describe  programs I used the
State Monad for:

1) You can find a portion of the code here: http://hpaste.org/7809

The purpose of this program was extracting address parts (PO box, street,
city, country, postal code, ...) from addresses which are composed of a
name, 3 free text lines and a zip code. The state is a list of AddressPart
elements. If you look at the extractAddress function, it contains many other
function running in the State Monad. Each function can get and put the
state. The state will contain both unparsed and already parsed AddressPart
elements.

The big benefit I got from using the State Monad was that I was able to
reorder the functions by just copy/pasting the function name from one place
to another.

Each of the `State Address ()` function will get the state, try to find an
address part in the unparsed AddressPart elements and put a new State with
the recognized AddressPartS if any.

I think parsing is a common use case for the State Monad where you want to
store the unparsed data along with the parse result and don't want to care
about passing those elements from one function to another.

2) I also recently used the State Monad Transformer to build a single
Data.Map from a set of different files. The State is the Data.Map and the
action in the runStateT is a mapM_ over a list of file names.

processFile :: String - StateT (PartsMap B.ByteString) IO ()
-- get the Map
-- add the file info
-- put the Map

runStateT (mapM_ processFile fileNames) M.Empty
-- each processFile call will get access to the result of the previous call
and put the updated Map.

I don't know if it's a common use case for the State Monad, but I found it
useful. I could probably have used foldM to achieve the same goal and don't
worry about using the State Monad.

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie: State monad example questions

2008-05-21 Thread Olivier Boudry
On Wed, May 21, 2008 at 8:42 AM, Dmitri O.Kondratiev [EMAIL PROTECTED]
wrote:

 So let's start with fundamental and most intriguing  (to me) things:

 getAny :: (Random a) = State StdGen a
 getAny = do g - get -- magically get the current StdGen

 First line above declares a data type:

 State StdGen a

 which is constructed with the function:

 State {runState :: (StdGen - (a, StdGen))}

 Q1: Where in the example (
 http://www.haskell.org/all_about_monads/examples/example15.hs) data of
 this type *actually gets constructed* ?


In getAny and getOne. Their signature has type `State StdGen a`. The use of
the do notation to chain the actions and the use of get and put from the
State Monad make this function a `State StdGen a`.


 Looking at example15.hs code we see the following sequence:

 1) makeRandomValue g -- where g is a StdGen instance, ok

 2) makeRandomValue g ~ expands into ~

 ~  (runState (do { ...; b - getAny;...})) g


 This last expression puzzles me. I can understand, for example, this:

 State StdGen a :: aState
 StdGen:: g1

 (v, g2) = (runStae aState) g1 -- this returns a state function which is
 then passed a generator g1, and as result returns pair (value, new generaor)

 But '(runState (do ...)) g' implies that expression (do ...)  must be
 somehow of type 'State StdGen a' ?
 Yet, when we call 'makeRandomValue g' we just pass to this function
 g::StgGen

 So, my next question:
 Q2: How (do {...;b - getAny;...}) becomes an *instance* of type 'State
 StdGen a' ?


In 2) I suppose you're talking of `makeRandomValueST` as `makeRandomValue`
is the function that runs without the State Monad.

makeRandomValueST does not build a `State StdGen a` it uses `runState` to
run the (do block) which has type `State StdGen a`.

Using `runState` will run an action which has `State s a` type on an initial
state `s` and return a `(a, s)` tuple.

`makeRandomValueST` does just the same using its parameter `g :: StdGen` as
initial state and returning a tuple of type `(MyType, StdGen)`. Now what
makes the do-block used in `runState` an instance of type `State StdGen a`
is type inference. `runState` expects a `State s a` as first argument and
`s` as second argument. The function signature, the use of `=` and
`return` (desugared do-block) to combine actions and the use of actions
already having that type like `getAny` and `getOne` will make your do block
a `State StdGen a`.

I'm not sure we can talk of building an instance of `State s a`. It's a
parameterized variant of `State s a` which itself is an instance of the
Monad class. We're just assigning types to the `s` and `a` type variables in
`State s a`.

In short `runState` takes the value (s - (a, s)) out of the State monad. In
the case of the State Monad that value is a function and it is run on the
initial state. Its usually what runX functions do. They have type
`(Monad m) = m a - a`.

Actions in the State Monad have type `State (s - (a, s))`. The value stored
in the State constructor is a function. Combining two actions using the
`=` and `` functions (hidden or not in a do-block) just create a bigger
`s - (a, s)` function. The function is hidden in a `State` constructor
just to ensure you don't run it when you don't want to. When you whant to
run the big function you first have to take it out of the State
constructor using the accessor `runState` and then run it on the initial
state. The end result is of course a (a, s) tuple.

Clear as mud, isn't it? It tooks me lots of time to understand how the State
Monad works. I read many tutorial and still understood nothing about it. Its
only by looking at the source code, playing with it and trying to rewrite
the State Monad that I finally got an understanding of it. So I'm not sure
you'll get it before you go through the same kind of path.

The key to understand this Monad, at least based on my experience, is to
keep in mind that `=` just assembles small state passing functions into
bigger ones, but does not run the built function until you explicitly use
the `runState` function on it.

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How does GHC read UNICODE.

2008-05-20 Thread Olivier Boudry
On Mon, May 19, 2008 at 10:32 PM, L.Guo [EMAIL PROTECTED] wrote:


Does GHC support it now ? or, is there any other way to do this ?


Hi,

The following blog article may help:

http://blog.kfish.org/2007/10/survey-haskell-unicode-support.html

It's a comparison of the different libraries for dealing with Unicode in
Haskell (utf8 in source, iconv, utf8-string, encoding).

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie: State monad example questions

2008-05-20 Thread Olivier Boudry
2008/5/19 Dmitri O.Kondratiev [EMAIL PROTECTED]:

 I am trying to understand State monad example15 at:
 http://www.haskell.org/all_about_monads/html/statemonad.html


Hi Dmitri,

I'm not sure you need to understand everything about Monad and do-notation
to use the State Monad. So I will try to explain its use without talking
about those scary topics. ;-)

In Haskell you use the state monad when you want to hide state passing
between function calls. As Haskell is pure you cannot change state. You can
just create a new state and return it along with the value. In haskell you
would do this by returning the value and new state in a tuple. State passing
functions usually have the type `s - (a, s)` where a is the type of the
return value and s is the type of the State.

This is exactly what the `random` function does. It gets a state and returns
a tuple made of a value and a new state (StdGen: is a new seed for the
random generator) to be used on the next `random` function call .

Without the state monad you have to explicitely pass the new seed between
calls to `random` as using the same seed for all function calls would always
give you the same not so random number.

Explicit state passing would look like this.

get3RandomInts :: StdGen - (Int, Int, Int)
get3RandomInts g1 =
let (r1, g2) = random g1
(r2, g3) = random g2
(r3, _)  = random g3
in (r1, r2, r3)

It's tedious, unreadable and error prone as it's easy to mess up the
numbering (based on my experience).

The State Monad allow you to hide the state passing. You don't have to give
the state as an argument and your function won't return a changed state
along with the data. Code running in the State Monad will look like this:

getAny :: (Random a) = State StdGen a
getAny = do g - get -- magically get the current StdGen
let (x, g') = random g
put g' -- magically save the new StdGen for later
return x

get3RandomIntsWithState :: State StdGen (Int, Int, Int)
get3RandomIntsWithState = do
r1 - getAny -- you don't care about stdgen passing
r2 - getAny
r3 - getAny
return (r1, r2, r3)

To use your get3RandomIntsWithState function you need to run it using one of
runState (returns the (value, state)) or evalState (returns the value).

main :: IO ()
main = do
g - getStdGen
let t = evalState get3RandomsWithState g
print t

The interesting bits are in the getAny function. The State Monad provides
you with 2 new function, get and set. If you look at this function as
blackboxes; `get` will retrieve the current State and `put` will save a new
State. You don't need to worry about how the State is passed from one getAny
function call to another as long as they're run in the same `evalState`
call.

Now getAny can be simplified. If you look at the random function and at the
State newtype declaration you will see that a State is a `s - (a, s)`
function hidden in the State constructor.

newtype State s a = State {runState :: s - (a, s)}

random is also of the type `s - (a, s)` even if variables are labelled `g`
and `a`

random :: (RandomGen g, Random a) = g - (a, g)

So wrapping the random function into the State constructor will just give
you a getAny function for free.

getAny :: (Random a) = State StdGen a
getAny = State random

I put a copy of the code in http://hpaste.org/7768

In short to use the State monad, you just need to care about a couple of
details.

The type of your functions running in the State Monad must end in `State s
a` where `s` is the type of the state and `a` the type of the return value.

You have to run it using either runState, execState or evalState. runState
will return both the value and the state, execState will return the state
and evalState will return just the value.

You must use put and get to retrieve and store the State but don't need to
care about the details of how the state is passed. As long as your function
calls are all part of the same action.

I hope it helps. I'm also quite new at Haskell and the terminology used is
probably not very accurate.

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI: newbie linking problem

2008-05-15 Thread Olivier Boudry
Hi all,

I found a solution to my linking problem, but it's a bit scary and I'm
wondering if there is a simpler way to do this:

The solution comes from the following article:
http://www.emmestech.com/moron_guides/moron1.html

To get ghc to link my dll properly I had to do the following:

1. Create a .def file from the sapnwrfc.lib using pexports.exe:
'pexports sapnwrfc.lib  sapnwrfc.def'

2. Edit the sapnwrfc.def file to add @24 at the end of the function I must
call.
...
RfcSubmitTransaction
RfcTraceTest
[EMAIL PROTECTED] -- here
...

3. Create a 'sapnwrfc.a' import library using dlltool:
'dlltool --input-def sapnwrfc.def --dllname sapnwrfc.dll
--output-lib libsapnwrfc.a -k'

Is there a simpler way to do this? Some way of tricking ghc to search for
RfcUTF8ToSAPUC instead of [EMAIL PROTECTED] It looks like ghc/ld/gcc
(whoever is responsible) adds a @24 (number depends of args) at the end of
the function name when the function is called using stdcall convention.

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] runInteractiveCommand: program ends before writing or reading all the output

2008-05-15 Thread Olivier Boudry
On Thu, May 15, 2008 at 2:42 PM, Ronald Guida [EMAIL PROTECTED] wrote:

 It looks like a simple race condition to me.  You are using
 waitForProcess pid to wait for runInteractiveCommand to finish, but
 you don't seem to have anything that waits for createDefFile to
 finish.


Thanks Ronald,

As I could not find a function to wait on a ThreadId I used a MVar to
synchronize both threads.

   sync - newEmptyMVar
   forkIO (createDefFile sync file out)
   waitForProcess pid
   takeMVar sync

and at the end of the forked thread:

   putMVar sync ()

Is this normal or have I missed the `waitOnThreadId` function?

Thanks for all the comments received on this thread,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] getting output from shell commands

2008-05-15 Thread Olivier Boudry
Hi Philip,

I just asked a question to the list about using runInteractiveCommand. You
may find the code useful but will need to either remove the forkIO
instruction or synchronize the two threads using a MVar to avoid the
concurrency problem I had.

You'll find the thread here:

http://www.haskell.org/pipermail/haskell-cafe/2008-May/042975.html

Regards,

Olivier.

On Thu, May 15, 2008 at 3:18 PM, Philip Müller [EMAIL PROTECTED]
wrote:

 Hi,

 I would like to be able to run a shell command like curl and process the
 output in my Haskell program, but I couldn't find anything helpful about it.

 Something like

 main = do
args - getArgs
inp - exec curl args
putStrLn (processInput inp)

 would be very helpful.

 Regards
 Philip
 ___
 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] runInteractiveCommand: program ends before writing or reading all the output

2008-05-15 Thread Olivier Boudry
On Thu, May 15, 2008 at 6:23 PM, Duncan Coutts [EMAIL PROTECTED]
wrote:


 On Thu, 2008-05-15 at 13:40 -0400, Olivier Boudry wrote:
 As an example let me show you as an example how we use it in Cabal:


Hi Duncan,

I tried to place a length text `seq` before the mapM_ writeExport to force
the process output to be read but the result was even worst (only one line
printed). Apparently withtout the `evaluate` function it causes more
troubles than it solves.

The example you provided is really helpful. I learned a lot reading it.

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI: newbie linking problem

2008-05-14 Thread Olivier Boudry
On Wed, May 14, 2008 at 5:46 PM, Bulat Ziganshin [EMAIL PROTECTED]
wrote:

 use stdcall instead of ccall in Haskell too. afair, depending on
 calling conventions, different prefixes/suffixes are used when
 translating C function name into assembler (dll) name


Oops, sorry I copied the wrong line in my e-mail. I'm using stdcall in the
foreign import. I first tried with ccall and then realized the header was
defining the stdcall convention when built on windows. The link error occurs
when I use stdcall. When I use ccall it links but gives segmentation faults
when I run the program.

Here is the last import I used.
foreign import stdcall unsafe sapnwrfc.h RfcUTF8ToSAPUC
  f_RfcUTF8ToSAPUC :: RfcBytePtr - CUInt - SapUCPtr - Ptr CUInt - Ptr
CUInt - RfcErrorInfoPtr - IO RfcRetCodeType

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] hsc2hs: expanding macros in the .hsc file

2008-05-13 Thread Olivier Boudry
Hi all,

Is it possible to expand macros defined in includes into the .hsc file? I'm
trying to call functions from a library written in C. The library can be
used with or without Unicode chars, depending on #define instructions.

The library has macros for all the standard functions used to work on
strings (malloc, strlen, strcpy, strtok, ...). So that in code using the
library one can always call the macro and don't care about the char type
(strlenU instead of wcslen or strlen). Macro expansion will define which
function will be used depending on the SAPwithUNICODE #define. I put a very
simplified example below. The original file contains much more conditions
(OS, Unicode or not, little or big endian, ...).

#define strlenU SAP_UNAME(strlen)

#ifdef SAPwithUNICODE
  #define SAP_UNAME(name)name##U16
#else
  #define SAP_UNAME(name)name
#endif

#if defined(WCHAR_is_2B)
  #define strlenU16   wcslen
#endif

I would like to be able to expand strlenU in my .hsc file and get the
correct function.

foreign import ccall static sapuc.h strlenU
  f_strlenU :: Ptr (#type SAP_UC) - IO (#type size_t)

I would like to be able to expand the strlenU macro to the real function
name (wcslen or strlen). Is there a way to do this?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] FFI: Creating a Storable for a C-struct composed of char arrays

2008-05-09 Thread Olivier Boudry
Hi all,

I'm trying to make RFC calls to SAP using the nwsaprfc library. Some structs
defined in the library contains arrays (byte or word arrays). For example:

typedef struct _RFC_ATTRIBUTES
{
SAP_UC dest[64+1];  /* RFC destination  */
SAP_UC host[100+1]; /* Own host name*/
SAP_UC partnerHost[100+1]; /* Partner host name*/
SAP_UC sysNumber[2+1]; /* R/3 system number*/
SAP_UC sysId[8+1];  /* R/3 system name  */
SAP_UC client[3+1]; /* Client   */
SAP_UC user[12+1];  /* User */
SAP_UC language[2+1];   /* Language */
   ... continued
}}RFC_ATTRIBUTES, *P_RFC_ATTRIBUTES;

I would like to create a Haskell Storable counterpart of this structure.
Using http://therning.org/magnus/archives/tag/hsc2hs as an starting point, I
could create Storable for structures containing fields with basic types.

Before working on the real data structures I wrote a more simple example to
play with:

-- File: ArrayStruct.h --
typedef struct _ArrayStruct
{
char a[10+1];
char b[20+1];
char c[30+1];
} ArrayStruct, *P_ArrayStruct;

-- File: ArrayStruct.c --
#include ArrayStruct.h

void
print_array_struct(ArrayStruct *f)
{
printf(%s\n, __FUNCTION__);
printf(f-a: %s\n, f-a);
printf(f-b: %s\n, f-b);
printf(f-c: %s\n, f-c);
}

-- File: HArrayStruct.hsc
{-# OPTIONS -ffi #-}
module Main
  where

import Foreign
import Foreign.C.Types

#include ArrayStruct.h

data HArrayStruct = HArrayStruct { a :: String, b :: String, c :: String }
type HarrayStructPtr = Ptr HArrayStruct

foreign import ccall static ArrayStruct.h print_array_struct
f_print_array_struct :: ArrayStructPtr - IO ()

instance Storable HArrayStruct where
  sizeOf _ = (#size ArrayStruct)
  alignment _ = alignment (undefined :: CInt)
  peek _ = error peek is not implemented
  poke ptr (HArrayStruct a' b' c') = do
(#poke ArrayStruct, a) ptr a'
(#poke ArrayStruct, b) ptr b'
(#poke ArrayStruct, c) ptr c'

printArrayStruct as = with as f_print_array_struct

main = printArrayStruct $ HArrayStruct { a=some, b=test, c=data }

-- End of files

Of course it won't work as HArrayStruct in file HArrayStruct.hs uses Strings
and String is not an instance of Storable.

Ideally I would need some sort of Storable array of char. Is
Data.Storable.Array the type I'm looking for? Could someone point me to some
code using the same kind of structures?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI: Creating a Storable for a C-struct composed of char arrays

2008-05-09 Thread Olivier Boudry
Hi Brandon,

Thanks for your help, CString will work great for Char arrays, but what
about the 16bit-Word arrays? I was not clear in my previous post but the
structures used in the nwrfcsdk library can use 8bit or 16 bit chars
depending on a #define (#define SAPwithUNICODE).

Reading another post on FFI in this mailing list I found a link to the
following page http://haskell.org/haskellwiki/Modern_array_libraries with a
section on StorableArrayS. I'm now trying to use this example code to get
StorableArray to work.

I will try to use Data.Encoding to convert Haskell StringS to ASCII or UTF16
ByteStringS. Then unpack those ByteStringS to Word8 list and populate
StorableArrayS with the bytes. I hope it'll do the job for both Word8 and
Word16 arrays.

Olivier.

On Fri, May 9, 2008 at 9:52 AM, Brandon S. Allbery KF8NH 
[EMAIL PROTECTED] wrote:


 On 2008 May 9, at 9:42, Olivier Boudry wrote:

 Of course it won't work as HArrayStruct in file HArrayStruct.hs uses
 Strings and String is not an instance of Storable.

 Ideally I would need some sort of Storable array of char. Is
 Data.Storable.Array the type I'm looking for? Could someone point me to some
 code using the same kind of structures?


 You want CString (Foreign.C.String).

 --
 brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
 system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
 electrical and computer engineering, carnegie mellon universityKF8NH



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Shouldn't this loop indefinitely = take (last [0..]) [0..]

2008-04-03 Thread Olivier Boudry
Hi all,

If you compile and run this:

main = do
  putStrLn $ show $ take (last [0..]) [0..]

or simply run:

take (last [0..]) [0..]

in ghci, it first hang for about one minute and then starts to generate an
infinite list. I was expecting last [0..] to never produce a value and the
take function to never take from the [0..] list.

I found that line of code in a friend's Skype Message, lauched it in ghci
and forgot it. When I came back to my ghci window a couple minutes later it
was listing numbers, which was really unexpected.

If I just run last [0..] it doesn't return a value and my computer will
quickly start to paginate to death. Am I missing something? Some laziness
magic? Rewrite rules?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Shouldn't this loop indefinitely = take (last [0..]) [0..]

2008-04-03 Thread Olivier Boudry
On Thu, Apr 3, 2008 at 10:35 PM, Bryan O'Sullivan [EMAIL PROTECTED]
wrote:


 It's not an infinite list.  It's a list of length maxBound::Int, as
 required by the fact that take's first argument is an Int.  The second
 argument is probably defaulting to Integer.


Right! The first arg of take makes the first list into a int list. I did
not wait long enough to see the end of the list and I'm so used to represent
infinite lists with [0..] that I didn't think it could be limited.

Thanks for the explanation!

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Shouldn't this loop indefinitely = take (last [0..]) [0..]

2008-04-03 Thread Olivier Boudry
On Thu, Apr 3, 2008 at 11:13 PM, Don Stewart [EMAIL PROTECTED] wrote:

 length, take, drop and index working on machine-sized Ints by default
 are really a bit of a wart, aren't they?

 -- Don


Agreed,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Fw: hdbc odbc also crashes on 6.8.2 Re: [Haskell-cafe] HDBC-ODBC crashes on ghc 6.8

2007-12-15 Thread Olivier Boudry
On Dec 14, 2007 12:37 PM, Thomas Hartman [EMAIL PROTECTED] wrote:



 I just tried HDBC-ODBC on 6.8.2, but it still crashes. Works on 6.6.1.

 thomas.


Hi Thomas,

I tried to compile your minimal app on 6.8.2 and get the following result.

C:\Tempghc --make TestHDBC.hs
Linking TestHDBC.exe ...
C:\Program Files\Haskell\HDBC-
odbc-1.1.3.0\ghc-6.8.2/libHSHDBC-odbc-1.1.3.0.a(Co
nnection.o)(.text+0x52c):fake: undefined reference to `SQLAllocHandle'
C:\Program Files\Haskell\HDBC-
odbc-1.1.3.0\ghc-6.8.2/libHSHDBC-odbc-1.1.3.0.a(Co
nnection.o)(.text+0x5b8):fake: undefined reference to `SQLSetEnvAttr'
... (long list of undefined references)...

When running it using ghc -e main it gives no error, but when compiling I
get those undefined reference errors. The functions listed here are defined
in ghc-lib\libodbc32.a and using filemon I could see that the library is
found and opened from ld.exe during linking. I don't understand why it
cannot link to those functions.

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing unstructured data

2007-12-05 Thread Olivier Boudry
On Nov 29, 2007 5:31 AM, Reinier Lamers [EMAIL PROTECTED] wrote:

 Especially in the fuzzy cases like this one, NLP often turns to machine
 learning models. One could try to train a hidden Markov model or support
 vector machines to label parts of the string as name, street,
 number, city, etc. These techniques work very well for part of
 speech tagging in natural language, and this seems similar. However, you
 need a manually annotated set of examples to train the models. If you
 really have a big load of data and it seems like a good solution, you
 could use an off-the-shelf part-of-speech tagger like SVMTool
 (http://www.lsi.upc.edu/~nlp/SVMTool/http://www.lsi.upc.edu/%7Enlp/SVMTool/)
 to do it.

 Reinier


Hi Reinier,

Thanks for the link to SVMTool. I don't have the basis to understand most of
the NLP articles I found and get stuck on the first NLP's slang words. For
me using an existing tool will be easier than build a new one. I'm currently
looking at the tool's documentation and it looks quite promising. It seems
to be very generic and highly reusable.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing unstructured data

2007-12-03 Thread Olivier Boudry
On 12/2/07, Steven Fodstad [EMAIL PROTECTED] wrote:

 Sorry for not responding earlier.  The haskell-cafe list is hard to keep
 up with.

 The process of finding geographic (lat/long) coordinates from a text
 address is called geocoding.  Obviously extracting the parts of an
 address is part of that, so you might find better results looking for
 geocoding, rather than the more general and more difficult topic of
 extracting structure from unstructured data.  Unfortunately, I don't
 have any references at hand on that part of geocoding.


Hi Steven,

The idea of using the geocoding approach seems appealing. I already thought
of using geocoding for address validation (after the parsing) but not of
looking at how geocoding tools parse addresses. But I'm not sure geocoding
tools would be suitable to handle my addresses. I used a few geocoding tools
and usually you have to provide the address in a very specific format if you
want it to be recognized. Also most of the time it work quite well for US
addresses but not for other countries addresses.

I need to recognize very specific parts of an address. More than what a
geocoding tools will require. Like dock #, doors, suite #, contact person,
etc...

I'm currently using the ZipFourCE web service from BCCSoftware for
validating my addresses against the USPS address database. This tool is
built for parsing and correcting addresses but I just use it for validation
as it's not smart enough to parse them or maybe they are just too
scrambled for the parsing to be automated using an out of the box tool. ;-)

Thanks for your input,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsing unstructured data

2007-11-28 Thread Olivier Boudry
Hi all,

This e-mail may be a bit off topic. My question is more about methods and
algorithms than Haskell. I'm looking for links to methods or tools for
parsing unstructured data.

I'm currently working on data cleaning of a Customer Addresses database.
Addresses are stored as 3 lines of text without any structure and people
made used lots of imagination to create the data (20 years of data using no
rules at all). Postal code, street, city, state, region, country and other
details as suite, building, dock, doors, PO box, etc... are all stored in
free form in those 3 lines.

I already wrote a haskell program to do the job. It correctly parses about
2/3 addresses and parses much of the rest but with unrecognized parts left.
The current program works by trying to recognize words used to tag parts
like STE, SUITE, BLDG, street words (STR, AVE, CIRCLE, etc...) and countries
from a list (including typos). It uses regular expressions to recognize
variation of those words, lookup tables for countries, street words, regular
expression rules for postal codes, etc... The most difficult task is
splitting the address parts. There is no clearly defined separator for the
fields. It can be dot, space, comma, dash, slash, or anything you can
imagine using as a separator and this separator can of course also be found
inside an address part.

In the current application when part of an address is recognized it will not
be parsed again by the other rules. A system trying all rules and tagging
them with probabilities would probably give better results.

Any link to tools or methods that could help me in that task would be
greatly appreciated. I already searched for fuzzy, probabilistic or
statistical parsing but without much success.

Thanks,

Olivier.

PS: just in case someone's interested I attached the code and partial data
to this e-mail.


parseaddresses.tar.gz
Description: GNU Zip compressed data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing unstructured data

2007-11-28 Thread Olivier Boudry
On 11/28/07, Hans van Thiel [EMAIL PROTECTED] wrote:

 Have you looked at the Java Rule Engine (I believe JSR 94) and in
 particular Jess?
 http://herzberg.ca.sandia.gov/

 I have no experience with it myself, though, just heard of it.

 Regards,

 Hans van Thiel


Hi Hans,

Never heard of that tool but it looks interesting. I will definitely give it
a try.

Thanks for the link,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell and DB : giving up

2007-11-28 Thread Olivier Boudry
On Nov 28, 2007 1:11 PM, manu [EMAIL PROTECTED] wrote:

 Hello

 I've spent a few days trying to install all the packages required to
 use HaskellDB with either MySQL or SQlite3
 (the only 2 DB the host I was thinking about is supporting)

 Well, I am giving up ! I seriously regret replacing ghc-6.6 with
 ghc-6.8, I didn't expect that building packages would be so ...
 unsucessfull and time-wasting.

 I just thought I'd let you know what's in store for PHP-style-users-
 like-me who want to use a database with ghc-6.8.1 at the moment, the
 hurdle is high !

 I hope these packages will be fixed soon (I can't figure how to fix
 them myself obviously).

 And now I'm going to stay away from my computer for a while :)

 cheerio

 M


Hi Manu,

I built HSQL MySQL on Windows using GHC-6.8.1. I had to replace the
Setup.lhs file be able to build with Cabal-1.2.2.0 (I found a working one on
the web) and had to modify the cabal file (build-depends list). If you're
interested I attached a copy of the two files.

HSQL also comes with a SQLite module but I didn't tried it.

The problems I encountered when compiling using GHC 6.8.1 are almost always
the same and are very well described in this document:
http://haskell.org/haskellwiki/Upgrading_packages.

Usually you just have to adapt the build-depends list and change the imports
of Data.ByteString.Base which was split in Internal and Usafe. It sometimes
requires some try/error iterations.

Using this information I was able to build many modules on Win32 / GHC
6.8.1without problems (HTTP, HaXmL, polyparse, exif, gtk2hs, hxt,
regex-pcre,
compact-string). It can be more complicated when the package do not use a
simple build script (as was the case for HSQL).

Best regards,

Olivier.


HSQL-MySQL-6.8.1.tar.gz
Description: GNU Zip compressed data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing unstructured data

2007-11-28 Thread Olivier Boudry
On 11/28/07, Grzegorz Chrupala [EMAIL PROTECTED] wrote:

 You may have better luck checking out methods used in parsing natural
 language. In order to use statistical parsing techniques such as
 Probabilistic Context Free Grammars ([1],[2] ) the standard approach is to
 extract rule probabilities from an annotated corpus, that is collection of
 strings with associated parse trees. Maybe you could use your 2/3 of
 addresses that you know are correctly parsed as your training material.

 A PCFG parser can output all (or n-best) parses ordered according to
 probabilities so that would seem to be fit your requirements.
 [1] http://en.wikipedia.org/wiki/Stochastic_context-free_grammar
 [2] http://www.cs.colorado.edu/~martin/slp2.html#Chapter14
 --
 Best,
 Grzegorz
 --


Hi Grzegorz,

Wow, Natural Language Processing looks quite complex! But it also seems to
be closely related to my problem. If someone finds a NPL for dummies
article or book I'm interested. ;-)

Thanks for your help,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal under windows (was Re: Haskell-Cafe Digest, Vol 51, Issue 180)

2007-11-28 Thread Olivier Boudry
On 11/28/07, Tim Docker [EMAIL PROTECTED] wrote:


  Well I'd say none of the packages I've tried, build out of the box...

 I'm not a windows developer, but

 Is it actually reasonable to expect any cabal packages that depend on
 external c libraries and headers to build out of the box on windows? How
 can cabal find out where those files are, without requiring a config
 file to be edited?

 Tim


Tim,

It is reasonable if you set the LIB and INCLUDE environment variables to
point to the MSYS /usr/local/lib and /usr/local/include directories. Of
course you'll have to build the c library from source in MSYS/MinGW for this
to work. You'll also have to manually copy the dll files to a location in
the PATH.

set LIB=%LIB%;C:\MSYS\1.0\local\lib
set INCLUDE=%INCLUDE%;C:\msys\1.0\local\include

You can this as a one time change in the Systems control panel.

If you install the C library from a binary distribution (usually installed
in some arbitrary location on the pc) then the easiest way is to edit the
cabal file.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A tale of Project Euler

2007-11-27 Thread Olivier Boudry
On 11/27/07, Andrew Coppin [EMAIL PROTECTED] wrote:

 Hi guys.

 Somebody just introduced me to a thing called Project Euler. I gather
 it's well known around here...

 Anyway, I was a little bit concerned about problem #7. The problem is
 basically figure out what the 10,001st prime number is. Consider the
 following two programs for solving this:

 First, somebody else wrote this in C:

 int n = 2 , m , primesFound = 0;

 for( n=0;n  MAX_NUMBERS;n++ )
 if( prime[n] )
 {
 primesFound++;

 if( primesFound == 10001 )
cout  n   is the 10001st prime.  endl;

 for(m=2*n;mMAX_NUMBERS;m+=n)
prime[m]=false;
 }

 Second, my implementation in Haskell:

 primes :: [Integer]
 primes = seive [2..]
 where
   seive (p:xs) = p : seive (filter (\x - x `mod` p  0) xs)

 main = print (primes !! 1)

 Well, we know who's winning the beauty contest. But here's the worrying
 thing:

   C program: 0.016 seconds
   Haskell program: 41 seconds

 Eeeps! o_O That's Not Good(tm).

 Replacing primes :: [Integer] with primes :: [Word32] speeds the
 Haskell version up to 18 seconds, which is much faster but still a joke
 compared to C.

 Running the Haskell code on a 2.2 GHz AMD Athlon64 X2 instead of a 1.5
 GHz AMD Athlon drops the execution time down to 3 seconds. (So clearly
 the box I was using in my lunch break at work is *seriously* slow...
 presumably the PC running the C code isn't.)

 So, now I have a Haskell version that's only several hundred times
 slower. Neither program is especially optimised, yet the C version is
 drastically faster. This makes me sad. :-(

 By the way... I tried using Data.List.Stream instead. This made the
 program about 40% slower. I also tried both -fasm and -fvia-c. The
 difference was statistically insignificant. (Hey guys, nice work on the
 native codegen!) The difference in compilation speed was fairly drastic
 though, needless to say. (The machine is kinda low on RAM, so trying to
 call GCC makes it thrash like hell. So does linking, actually...)


 Also, I'm stuck with problem #10. (Find the sum of all primes less than
 1 million.) I've let the program run for well over 15 minutes, and still
 no answer is forthcomming. It's implemented using the same primes
 function as above, with a simple filter and sum. (The type has to be
 changed to [Word64] to avoid overflowing the result though.) The other
 guy claims to have a C solution that takes 12 ms. There's a hell of a
 difference between 12 ms and over half an hour...(!) Clearly something
 is horribly wrong here. Uh... help?

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


Hi Andrew,

I don't remember who I stole this prime computation from, but it is very
fast (10001's prime in 0.06 sec with Int and 0.2 with Integer on my machine)
and not overly complex:

primes :: [Integer]
primes = 2 : filter (l1 . primeFactors) [3,5..]
where
l1 (_:[]) = True
l1  _ = False

primeFactors :: Integer - [Integer]
primeFactors n = factor n primes
where
factor _ [] = []
factor m (p:ps) | p*p  m= [m]
| m `mod` p == 0 = p : factor (m `div` p) (p:ps)
| otherwise  = factor m ps

I used it a lot while playing with Euler Project. Many of the problems
require prime calculation.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A tale of Project Euler

2007-11-27 Thread Olivier Boudry
On 11/27/07, Sebastian Sylvan [EMAIL PROTECTED] wrote:

 That is indeed a nice and clear version that's pretty fast. It's
 basically the same as the C version except backwards (i.e. examine a
 number and work backwards through its divisors, rather than filling in
 a map of all multiples of a known prime).
 Let me suggest the following slight modification (primeFactors in your
 version doesn't actually return prime factors - it returns prime
 factors *or* a list of just the number itself),

 primes :: [Integer]
 primes = 2 : filter (null . primeFactors) [3,5..]

 primeFactors :: Integer- [Integer]
 primeFactors n = factor n primes
 where
 factor m (p:ps) | p*p  m= []
 | m `mod` p == 0 = p : factor (m `div` p) (p:ps)
 | otherwise  = factor m ps


 This is roughly 35% faster on my machine with GHC 6.7.20070730 too,
 but the point wasn't to make it faster, but clearer.
 --
 Sebastian Sylvan
 +44(0)7857-300802
 UIN: 44640862


Great remark, it's even simpler like this.

By the way I just found the article I stole this algorithm from:
http://www.haskell.org/haskellwiki/99_questions/31_to_41 last one in problem
35.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: GHC 6.8.1 and HDirect

2007-11-21 Thread Olivier Boudry
On 11/21/07, Fernand [EMAIL PROTECTED] wrote:

 Hi dear fellow ghc users,

 I simply wanted to let people know that I apparently succeeded in
 compiling  a patched version of HDirect with GHC 6.8.1 (with typelibs
 support).
 At least, I could compile some of the examples and had very simple test
 programs launch/connect to Word and Excel using automation. I lack time
 to really clean up the library (I did not made any Cabal patch and
 currently directly link with the « .a » and « .o » of the various
 modules), but feel free to contact me if you need some help to use
 hdirect with GHC 6.8.1.

 Sincerely yours,

 sL


Hi Fernand,

Congratulations! I once tried to compile HDirect with GHC 6.6.1 but finally
stopped trying after having made a bunch of unsuccessful modifications. It's
just too bad this library is no more maintained. Having a clean and
maintained COM interface would be really valuable for Haskell.

I would be interested in getting the patches for compiling HDirect with GHC
6.8.1.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: user error when using Text.Regex.PCRE

2007-11-20 Thread Olivier Boudry
On Nov 20, 2007 9:36 AM, ChrisK [EMAIL PROTECTED] wrote:

 Thank you very much for the error report.  I have tracked down the cause.

 You are searching against an empty Bytestring.  This is now represented by

  -- | /O(1)/ The empty 'ByteString'
  empty :: ByteString
  empty = PS nullForeignPtr 0 0

 And while the useAsCString and useAsCStringLen functions never reveal the
 null
 pointer, the current library uses unsafeUseAsCStringLen, which returns the
 null
 pointer.

 And this is getting caught by a null pointer check resulting in your
 crash.  I
 will post a fix later tonight, and announce it.

 Which regex-prce version are you using?  Perhaps from hackage?  I want to
 prioritize the version you need fixed.

 The earlier repository holds up to version 0.81 at
 http://darcs.haskell.org/packages/regex-pcre/
 The newer repository holds up to version 0.92 at

 http://darcs.haskell.org/packages/regex-unstable/regex-pcre/regex-pcre.cabal

 Out of further curiosity:

 Which version of the pcre library does it use?
 And what version of ghc?
 Which version of Data.ByteString?

 Cheers,
  Chris Kuklewicz



Hi Chris,

I'm using ghc-6.8.1, regex-pcre-0.92, bytestring-0.9.0.1 and libpcre-7.4.

Using your information, I might be able to workaround the problem by
filtering out empty bytestrings before applying the next regex.

Thanks for your reply,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] -O2 bug in GHC 6.8.1?

2007-11-20 Thread Olivier Boudry
On 11/20/07, Ian Lynagh [EMAIL PROTECTED] wrote:


 Hi Brad,

 I can't reproduce this. Can you please tell us what platform you are on
 (e.g. x86_64 Linux) and what gcc --version says?

 Also, where did your GHC come from, e.g. bindists from the download
 page, self-compiled?

 Also, as Christian says, it's best to file a bug report so that the
 problem doesn't get forgotten about.


 Thanks
 Ian


Hi Ian,

For info I can reproduce Brad's bug using ghc-6.8.1 (distributed binaries)
on Windows XP.

C:\Tempghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.1

C:\Tempbugo2.exe
23
24

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fun with Cabal on Windows! [Stream fusion for Hackage]

2007-11-20 Thread Olivier Boudry
On 11/19/07, Andrew Coppin [EMAIL PROTECTED] wrote:

 Well, I just tried to install this, and as per usual, Cabal has having
 none of it.

 C:\fusion\ runhaskell Setup configure
 Configuring stream-fusion-0.1.1...
 Setup: ld is required but it could not be found.


Hi Andrew,

I had the same problem with ghc-6.8.1 and solved it by adding C:\ghc\ghc-
6.8.1\gcc-lib to my PATH variable in environment variables. A copy of
ld.exeis in this directory.

In ghc-6.6.1, ld.exe was in the same place and it was working out of the box
for me. I don't understand why it is not found any more with ghc-6.8.1.

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Exposed module still hidden, why?

2007-11-20 Thread Olivier Boudry
On 11/20/07, Greg Fitzgerald [EMAIL PROTECTED] wrote:

 Using GHC 6.8.1 on Windows XP, after having used ghc-pkg to expose '
 directory-1.0.0.0', I am getting an error when I build haddock that says
 the package is hidden.  When I type ghc-pkg list, the package is not in
 parenthesis.  Typing ghc -v says that it is using the file from
 C:\ghc\ghc- 6.8.1\package.conf.  That package.conf file has the
 'exposed' set to True for that file.  Why does GHC still think the package
 is hidden?



Hi Greg,

You need to add directory to the Build-Depends instruction in the cabal
file. The base package has been split into separate modules in 6.8.1.

Build-Depends: base, directory

Look at this: http://groups.google.com/group/fa.haskell/msg/17a78c120ae26514

Cheers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] user error when using Text.Regex.PCRE

2007-11-19 Thread Olivier Boudry
Hi all,

I'm getting a strange user error when working with Data.ByteString.Char8 and
Text.Regex.PCRE.

Error I get is:
CustomerMaster: user error (Text.Regex.PCRE.ByteString died: (ReturnCode
0,Ptr
parameter was nullPtr in Text.Regex.PCRE.Wrap.wrapMatch cstr))

The part of the code causing problems is at the end of this e-mail. The
complete code is attached.

I'm working at cleansing customer addresses for a ERP system data migration.
The failing function is supposed to split some bytestrings using a list of
regular expressions (split on words like suite, building, attention, etc...)
stored in the tags binding. I use a foldl' to try each regular expression
on each address (addr is a list of address part, can be seen as a list of
bytestring values).

The funny and weird thing is that when I have only one regular expression in
tags, it works. When I have more than one regular expression in tags it
fails (user error) the first time one of the regular expression matches. A
match replaces the current address part with 3 new parts, before, match,
after. The next regular expression in the tags list will test the new before
and after parts. I presume it's the testing of those newly created parts
that causes the problem.

Any idea about what could go wrong here?

Thanks,

Olivier.

=== code ===

-- | Split unparsed address parts on keywords (suite, building, doors,
etc...)

splitOnTags :: AddressState
splitOnTags = do
  addr - get
  put $ foldl' f addr tags
  where
f a t   = concatMap (split t) a
split (T {partType = p, regex = r}) a@(AP X v)
  | BS.null y= [a]
  | otherwise = [AP X x, AE p, AP X z] -- new address parts
  where
(x, y, z) = match r v
split _ a = [a]

-- | Regex and part type representing tags used for splitting addresses

tags :: [Tag]
tags = [T AT
  (makeRegexOpts compCaseless execBlank
\\b(?:ATTN|ATTENTION|C/O)\\b[[:punct:]]?)
  (BS.pack ATTN: )
   ,T PB
  (makeRegexOpts compCaseless execBlank
\\b(?:(?:P\\.?\\s?O\\.?\\s*)BOX|C\\.P\\.|POSTFACH)\
\[[:punct:]]?\\s+(?:NO.\\s+)?)
  (BS.pack PO BOX: )
   ,T BLDG
  (makeRegexOpts compCaseless execBlank
\\b(?:BLDG|BUILDING|HANGAR)[[:punct:]]?)
  (BS.pack BLDG: )
   ,T DOCK
  (makeRegexOpts compCaseless execBlank
\\bDOCK[[:punct:]]?)
  (BS.pack DOCK: )
   ,T STE
  (makeRegexOpts compCaseless execBlank
\\b(?:SUITE|STE|APT|ROOM)[[:punct:]]?\
\\\s+(?:NO[[:punct:]]?)?)
  (BS.pack STE: )
   ,T UNIT
  (makeRegexOpts compCaseless execBlank
\\bUNIT[[:punct:]]?)
  (BS.pack UNIT: )
   ,T FLOOR
  (makeRegexOpts compCaseless execBlank
FLOOR)
  (BS.pack FLOOR: )
   ,T DOORS
  (makeRegexOpts compCaseless execBlank
\\bDOORS?[[:punct:]]?)
  (BS.pack DOORS: )]
module Main where

import Control.Monad.State
import qualified Data.ByteString.Char8 as BS
import Data.Char (isSpace)
import Data.List
import System.Environment
import System.IO
import Text.Regex.PCRE


-- Data declarations


-- | An address

type Address = [AddressPart]

-- | An address part (Suite, Dock, City, etc...) or a line separator

data AddressPart = AP AddressPartType BS.ByteString
 | AE AddressPartType -- tag found but not linked to text
 | S  AddressPartType -- line separator
 deriving (Show, Eq)

-- | Tags for address parts

data AddressPartType = I  -- Id
 | N  -- Name
 | PF -- Partner function
 | AT -- Attention
 | N2 -- Name 2
 | PB -- P.O. Box
 | BLDG   -- Building
 | DOCK   -- Dock
 | STE-- Suite
 | UNIT   -- Unit
 | FLOOR  -- Floor
 | DOORS  -- Doors
 | ST -- Street
 | CI -- City
 | CO -- Country
 | R  -- Region
 | Z  -- Zip code
 | X  -- Unparsed
 | E  -- Error message
 | L1 -- Start of Line 1
 | L2 -- Start of Line 2
 | L3 -- Start of Line 3
 | L4 -- Start of Line 4 (zip code)
 deriving (Show, Eq)

-- | The address state the program will run in

type AddressState = State Address ()

data Tag = T {partType :: AddressPartType,
  regex:: Regex,
  partName :: BS.ByteString}


Re: [Haskell-cafe] dropSpace not exported in ByteString

2007-11-16 Thread Olivier Boudry
On 11/16/07, Duncan Coutts [EMAIL PROTECTED] wrote:

 On Thu, 2007-11-15 at 21:55 -0500, Olivier Boudry wrote:

  By the way, what's the reason dropSpaceEnd is defined but not exported
  nor used through a rule? I'm just curious.

 We decided when trying to standardise the API to start with just the
 equivalents of the Data.List functions. We have tracked changes to
 Data.List, adding intercalate and isInfixOf.

 If there is a compelling reason to add dropSpaceEnd to the
 Data.ByteString API then the same would probably apply to Data.List and
 so it should be proposed for there and then Data.ByteString will track
 it too.

 Alternatively, someone should make the case for why it should be added
 to bytestring but not list. There is probably room for more string
 oriented list functions in some library somewhere (especially crazy
 Unicode stuff), like Data.String.

 Duncan


I understand the need for standardization. Having consistent functions
across modules is something I really appreciate in Haskell.

Thanks for the information,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] dropSpace not exported in ByteString

2007-11-16 Thread Olivier Boudry
Hi all,

I'm writing a Haskell program to do some address cleansing. The program uses
the ByteString library.

Data.ByteString.Char8 documentations shows functions for removing whitespace
from start or end of a ByteString. Those functions are said to be more
efficient than the dropWhile / reverse mixes.

It looks exactly like what I'm searching for, but apparently those functions
are not exported by the Data.ByteString.Char8 module. Are those functions
only called by rules? Transformation of dropWhile isSpace into dropSpace?
I've seen such a rule for dropSpace but did not found an equivalent rule for
dropSpaceEnd.

Is there a way to call the dropSpace and dropSpaceEnd or do I have to code
with dropWhile and hope that some rule will magically transform my
dropWhileS into dropSpaceS?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] dropSpace not exported in ByteString

2007-11-16 Thread Olivier Boudry
On 11/15/07, Don Stewart [EMAIL PROTECTED] wrote:


 Let me know if the rule fires. If it isn't, that's a bug, essentially.

 -- Don


Don,

As you can see the rule fires.

C:\Tempghc --make -O2 -fasm -ddump-simpl-stats DropSpaceTest.hs
...
3 RuleFired
1 FPS pack/packAddress
2 FPS specialise dropWhile isSpace - dropSpace
...

By the way, what's the reason dropSpaceEnd is defined but not exported nor
used through a rule? I'm just curious.

Best regards,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] dropSpace not exported in ByteString

2007-11-15 Thread Olivier Boudry
Hi Don,

In fact I'm not really looking at performance, I don't expect performance to
be a big issue in my application.

I was just looking at using some simple functions found in the documentation
and avoid redefining them.

In fact dropSpace and dropSpaceEnd are doing exactly what I'm looking for.
But of course if they're not exported it's not a problem and I'll use their
dropWhile equivalent.

Thanks for your reply,

Olivier.


On Nov 15, 2007 5:24 PM, Don Stewart [EMAIL PROTECTED] wrote:


 The latter:

FPS specialise dropWhile isSpace - dropSpace
dropWhile isSpace = dropSpace

 check that the rule fires with -ddump-simpl-stats

 There's no rule for dropSpaceEnd, but you can certainly inline the defn
 in your code, if perf. matters.

 -- Don

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie Question on Setting the GHC Search Path

2007-10-29 Thread Olivier Boudry
In GHC it works without the  and don't work with them:

Prelude :cd C:\Documents and Settings
Prelude :! pwd
C:\Documents and Settings

Olivier.

On 10/29/07, Benjamin L. Russell [EMAIL PROTECTED] wrote:

 Please pardon this intrusion for an elementary
 question on setting the GHC search path.

 I have installed GHC on my work Windows XP machine,
 and would like to be able to search for files in the
 following directory:

 D:\From C Drive\Documents and
 Settings\DekuDekuplex\Programming Practice\Haskell\GHC

 However, when I type the following command into the
 GHC interpreter:

 :cd D:\From C Drive\Documents and
 Settings\DekuDekuplex\Programming
 Practice\Haskell\GHC

 I get the following error message:

 *** Exception: D:\From C Drive\Documents and
 Settings\DekuDekuplex\Programming
 Practice\Haskell\GHC: setCurrentDirectory: invalid
 argument (Invalid argument)

 Yet, for testing purposes, when I type the following
 command:

 :cd cygwin

 I do not get any error message.

 There seems to be a problem with the spaces in the
 filename.  However, I would like to be able to use the
 D:\From C Drive\Documents and
 Settings\DekuDekuplex\Programming
 Practice\Haskell\GHC directory for GHC programming
 practice, because I keep my practice work for my other
 programming languages in the same
 super-super-directory.

 Does anybody know a way to specify D:\From C
 Drive\Documents and Settings\DekuDekuplex\Programming
 Practice\Haskell\GHC as a directory in the search
 path for GHC?

 Benjamin L. Russell
 ___
 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] Linking problems with a fresh gtk2hs build

2007-10-26 Thread Olivier Boudry
Hello,

I just built gtk2hs 0.9.12 using MinGW, GTK_2.0 and ghc-6.8.0.20071016. I
just changed some EXTERNALDEPS in the Makefile based on info found in the
following page http://haskell.org/haskellwiki/Grapefruit

25a126,128
 if HAVE_SPLIT_BASE
 tools_c2hs_c2hsLocal_EXTERNALDEPS += pretty containers array
 endif
358a362,364
 if HAVE_SPLIT_BASE
 libHSgtk_a_EXTERNALDEPS += containers array
 endif
1578a1585,1587
 if HAVE_SPLIT_BASE
 libHSsoegtk_a_EXTERNALDEPS += old-time
 endif

I had no problem building and installing the library but when trying to
compile the HelloWorld example to check the installation I get this error:

C:\Tempghc --make HelloGtk.hs
Linking HelloGtk.exe ...
C:/Progra~1/Haskell/lib/gtk2hs/libHSgtk.a(Gtk__1.o)(.text+0x419):fake:
undefined
 reference to `__stginit_gtkzm0zi9zi12_GraphicsziUIziGtkziLayoutziHPaned_'
collect2: ld returned 1 exit status

I found an irc log talking of using nm to track the problem. Tried nm and
got this (different from the problem specified in the irc log).

nm libHSgtk.a | grep
__stginit_gtkzm0zi9zi12_GraphicsziUIziGtkziLayoutziHPaned_
 U ___stginit_gtkzm0zi9zi12_GraphicsziUIziGtkziLayoutziHPaned_
c:\MinGW\bin\nm.exe: HPaned__4.o: File format not recognized
c:\MinGW\bin\nm.exe: MenuBar__48.o: File format not recognized

The missing symbol is found but I have a problem with the HPaned__4.o and
MenuBar__48.o of the libHSgtk.a file.

Any idea of what could have gone wrong?

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Linking problems with a fresh gtk2hs build

2007-10-26 Thread Olivier Boudry
More info on this problem:

I rebuilt the whole stuff using exactly the same method and working from a
new extract of the sources. Now I get the same kind of error but on another
object. This error looks a bit random!?!

nm.exe libHSgtk.a  /dev/null
C:\MinGW\bin\nm.exe: TextView__112.o: File format not recognized

I checked the other libraries and they all look OK except libHSgtk.a

Could it have something to do with split objects? I have hundreds of
TextView__... objects. I'm no trying to rebuild the whole stuff with
--disable-split-objs.

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?

2007-07-18 Thread Olivier Boudry

Hi Dmitri,

I built gtk2hs on Windows with GHC 6.6.1 and gtk2hs-0.9.11. Here's are the
steps that worked for me: (not sure I didn't missed some)

First you need to install a GTK+ development package for windows. I think
mine comes from http://gladewin32.sourceforge.net/modules/wfdownloads/

Then you must have MSYS and MinGW installed on your computer. You'll find
information on how to install this here:
http://hackage.haskell.org/trac/ghc/wiki/Building/Windows.

Once you've installed that stuff you can start a MSYS shell. You'll need to
set some environment variables for GTK (adapt to your path):
export GTK_BASEPATH=/c/GTK_2.0
export GTK_CONFIG_PATH=/c/GTK_2.0/lib/pkgconfig

Cd to the gtk2hs source directory and type:
./configure --prefix=/c/Progra~1/Haskell
make
make install

Hope this helps.

Good luck,

Olivier.

On 7/18/07, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote:



On 7/17/07, Malte Milatz [EMAIL PROTECTED] wrote:

 Dmitri O.Kondratiev:
  It looks like Graphics.SOE does not anymore exist  in GHC  6.6.1.
  Where one can get it or what to use  instead of it?

 You may try Gtk2Hs, which includes an implementation of SOE, called
 Graphics.SOE.Gtk.  (It works independently of the actual Gtk API.)  Use
 then the darcs version, because I remember an SOE bug fixed since the
 last release.

 Malte


Malte,
Thanks. The problem is that I need to run SOE on Win32.  When I try to run
a simple SOE app. in GHCi with Gtk2Hs Win32 release, this code:

module GWindow where
import Graphics.SOE.Gtk


main() =
runGraphics (
 do w - openWindow Graphics Test (300, 300)
drawInWindow w (text (100, 200) Hello Graphics
World)
k - getKey w
closeWindow w
)

displays a window and hangs.

I can get development release of Gtk2Hs with darcs, but how can I build it
on Win32?

Dima



--
Dmitri O. Kondratiev
[EMAIL PROTECTED]
http://www.geocities.com/dkondr

___
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] Shouldn't this be lazy???

2007-06-22 Thread Olivier Boudry

Hi all,

I'm playing with the TagSoup library trying to extract links to
original pictures from my Flickr Sets page. This programs first loads
the Sets page, open links to each set, get links to pictures and then
search for original picture link (see steps in main function).

It does the job, but for the tests I just wanted to take 10 links to
reduce the time the program runs. Just hoping that haskell laziness
would magically take the minimum amount of data required to get the
first 10 links out of this set of pages.

I did this replacing:
  (putStrLn . unlines . concat) origLinks
with
  (putStrLn . unlines . take 10 . concat) origLinks
in the main function.

With the last version of that line, I effectively only get 10 links
but the runtime is exactly the same for both main functions.

As I'm a newbie haskell programmer I certainly missing something.

By the way I know Flickr has an api I could use, but the purpose was
playing with TagSoup.

Thanks for any advice.

Olivier.

Here's the code:

module Main where

import Data.Html.TagSoup
import Control.Monad (liftM)
import Data.List (isPrefixOf, groupBy)
import Data.Maybe (mapMaybe)
import System (getArgs)
import System.Time
import IO (hPutStrLn, stderr)

base= http://www.flickr.com;
setsUrl name = /photos/ ++ name ++ /sets/

main :: IO ()
main = do
   args  - getArgs
   tStart- getClockTime
   setLinks  - getLinksByAttr (class, Seta) (base ++ setsUrl (args !! 0))
   picLinks  - mapM (getLinksByAttr (class, image_link)) setLinks
   origLinks - mapM (getLinksAfterImgByAttr (src,
http://l.yimg.com/www.flickr.com/images/icon_download.gif;)) $
(mapMaybe linkToOrigSize . concat) picLinks
   (putStrLn . unlines . concat) origLinks
   tEnd  - getClockTime
   hPutStrLn stderr ( timeDiffToString $ diffClockTimes tEnd tStart )

-- | extract all links from a tag types having given attribute
getLinksByAttr :: (String, String) - String - IO [String]
getLinksByAttr attr url = do
   sects - getSectionsByTypeAndAttr a attr url
   return $ hrefs sects

-- | get a tags following a img having a specific attribute
getLinksAfterImgByAttr :: (String, String) - String - IO [String]
getLinksAfterImgByAttr attr url = do
   sects - getSectionsByTypeAndAttr img attr url
   return $ hrefs $ map (dropWhile (not . isTagOpen) . drop 1) sects

-- | create sections from tag type and attribute
getSectionsByTypeAndAttr :: String - (String, String) - String - IO [[Tag]]
getSectionsByTypeAndAttr tagType attr url = do
   tags - liftM parseTags $ openURL $ url
   (return . filterByTypeAndAttr tagType attr) tags
 where
   filterByTypeAndAttr :: String - (String, String) - [Tag] - [[Tag]]
   filterByTypeAndAttr t a = sections (~== TagOpen t [a])

-- | extract href values from sections of a tags
hrefs :: [[Tag]] - [String]
hrefs = map (addBase . fromAttrib href . head)
 where
   addBase :: String - String
   addBase s | http://; `isPrefixOf` s = s
   addBase s | otherwise= base ++ s

-- | transform a link to a picture into a link to the original size picture
linkToOrigSize :: String - Maybe String
linkToOrigSize link =
   if parts !! 3 == photos then
   Just $ newUrl parts
   else
   Nothing
 where
   parts = map tail $ groupBy (const(/='/')) link
   newUrl p = http://www.flickr.com/photo_zoom.gne?id=; ++ p !! 5 ++
size=ocontext= ++ p !! 7
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Shouldn't this be lazy???

2007-06-22 Thread Olivier Boudry

Reading code like the following:

main = do
 s - getContents
 let r = map processIt (lines s)
 putStr (unlines r)

I was thinking all IO operations were lazy. But in fact it looks like
getContents is lazy by design but not the whole IO stuff.

Thank you all for your helpful answers,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Shouldn't this be lazy???

2007-06-22 Thread Olivier Boudry

Marc,

Thanks for the link. Your LazyIO monad is really interesting. Do you
know if this construct exists in GHC? (this question was left open in
this thread)

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Shouldn't this be lazy???

2007-06-22 Thread Olivier Boudry

On 6/22/07, David Roundy [EMAIL PROTECTED] wrote:

Or make this lazy with:

 main = do ...
   origLinks - mapM (unsafeInterleaveIO . getLinksAfterImgByAttr ...) 
picLinks
--
David Roundy
Department of Physics
Oregon State University


Just for info I used your tip to bring laziness into the function that
fetches the URLs. Work great and lazy now!

-- | create sections from tag type and attribute
getSectionsByTypeAndAttr :: String - (String, String) - String - IO [[Tag]]
getSectionsByTypeAndAttr tagType attr url = do
   tags - unsafeInterleaveIO $ liftM parseTags $ openURL $ url
   (return . filterByTypeAndAttr tagType attr) tags
 where
   filterByTypeAndAttr :: String - (String, String) - [Tag] - [[Tag]]
   filterByTypeAndAttr t a = sections (~== TagOpen t [a])

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Thread blocked indefinitely problem when playing with signals and MVar on Windows

2007-06-14 Thread Olivier Boudry

Hi all,

I'm playing with signal handlers on Win32. I found a good post on
signal handlers but it works with System.Posix.Signals which on Win32
is empty.

Blog is here: http://therning.org/magnus/archives/285

I tried to adapt this code to GHC.ConsoleHandler, the Win32
counterpart of System.Posix.Signals.

The code:
=
module Main where

--import System.Posix.Signals
import GHC.ConsoleHandler
import Control.Concurrent
import Control.Concurrent.MVar
import System

-- ControlC increments counter
handler :: MVar (Int, Bool) - ConsoleEvent - IO ()
handler mi ControlC = do
   (i, exit) - takeMVar mi
   putStrLn In ControlC handler
   putMVar mi ((i + 1), False)

-- Break sets Bool to True to stop application
handler mi Break = do
   (i, exit) - takeMVar mi
   putStrLn In Break handler
   putMVar mi (i, True)

-- Ignore other signals
handler _ _ = do return ()

doNothing :: MVar (Int, Bool) - IO ()
doNothing mi = do
   threadDelay 100
   (i, exit) - takeMVar mi
   if exit then do
   putStrLn Good bye!
   exitWith ExitSuccess
   else do
   putStrLn $ Repeating  ++ (show i)

main :: IO ()
main = do
   mi - newMVar (0, False)
   installHandler (Catch $ handler mi)
   sequence_ $ repeat $ doNothing mi
=

It compiles but when run I receive this:
Repeating 0
SignalsText.exe: loop

First iteration is executed but then it gets trapped in what looks
like a dead lock.

If I remove the installation of the signal handler to just have an
infinite loop (comment out installHandler ...) I get this:
Repeating 0
SignalsText.exe: thread blocked indefinitely

Without the signal handler the code uses only the main and doNothing
function and I can't figure out what causes this to block? Something
to do with my use of MVar, but what??? Lazy evaluation?

Thanks for any advice,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Thread blocked indefinitely problem when playing with signals and MVar on Windows

2007-06-14 Thread Olivier Boudry

I found my mistake. Through my copy/paste I ended up changing a
readMVar into a takeMVar leaving the MVar empty and having the main
thread blocking to read it.

Changed takeMVar to readMVar in doNothing and everything is working fine now.

Sorry for the noise,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Head and tail matching question

2007-06-11 Thread Olivier Boudry

Hi all,

I'm trying to write a untab function that would split a string on tabs
and return a list. Code is here.

import Data.List (break, unfoldr)
import Data.Char (String)

untab :: String - [String]
untab s = unfoldr untab' s

untab' :: String - Maybe (String, String)
untab' s | s ==  = Nothing
| otherwise = Just (h, ts)
where (h, t:ts) = break (== '\t') s

This code raises an exception when handling the last portion of the
string. Break returns a (something, ) and t:ts cannot match on .

I was wondering if there way a clean way of handling this last case
without adding tons of code. Some kind of idiomatic expression ;-)

Thanks,

Olivier.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe