Re: [Haskell-cafe] I don't understand how ST works

2012-06-09 Thread Nicu Ionita
Ok, the error was: I was using Control.Monad.ST.Lazy. Importing 
Control.Monad.ST compiles immediately without problem. (Is this because 
I'm using unboxed mutable vectors?)


Now, that's a little bit odd.

It's clear that the strict and lazy forms of ST are different types. But 
unfortunately they are named the same! So actually any error message 
from the compiler drives you crazy, because it's refering to another type.


Probably the reason to name the types with the same name is for easy 
interchangeability. But as we see, the types are not (always) 
interchangeable.


Anyway, now it compiles.

Thanks,
Nicu

Am 08.06.2012 23:15, schrieb Nicu Ionita:

Hi,

I created a gist with a minimal (still 111 lines) module:

https://gist.github.com/2898128

I still get the errors:

WhatsWrong.hs:53:5:
Couldn't match type `s' with `PrimState (ST s)'
  `s' is a rigid type variable bound by
  a type expected by the context: ST s [Move] at 
WhatsWrong.hs:48:21

In a stmt of a 'do' block: listMoves ml
In the second argument of `($)', namely
  `do { v - U.new maxMovesPerPos;
let ml = ...;
listMoves ml }'
In the expression:
  runST
  $ do { v - U.new maxMovesPerPos;
 let ml = ...;
 listMoves ml }

WhatsWrong.hs:65:44:
Couldn't match type `s' with `PrimState (ST s)'
  `s' is a rigid type variable bound by
  the type signature for nextPhaseOnlyCapts :: GenPhase s
  at WhatsWrong.hs:64:1
Expected type: U.MVector (PrimState (ST s)) Move
  Actual type: U.MVector s Move
In the return type of a call of `mlVec'
In the third argument of `genCapts', namely `(mlVec ml)'

Thanks,
Nicu

Am 08.06.2012 02:47, schrieb Silvio Frischknecht:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


Now comes my question: in the impure values there is always that
s. I was thinking that the whole structure should have s as a
parameter:

Yes


data MList s = MList { mlVec :: MVector s Move, mlNextPh :: MList
-

ST s (Maybe (MList s)) }

you probably meant:

 data MList s = MList { ... , mlNextPh :: Mlist s -  ... }

Now I'm not sure about your exact problem since the following compiles
for me.

 import Data.Vector
 import Data.Vector.Mutable
 import Control.Monad.ST

 type Move = ()
 data MList s = MList {
 mvVec :: MVector s Move,
 mlNextPh :: MList s -  ST s (Maybe (MList s)) }

 splitMove :: MList s -  ST s (Maybe (Move, MList s))
 splitMove ml = do
 m- unsafeRead (mvVec ml) 0
 undefined

Something you always have to watch out for when dealing with ST is not
to return something that depends on s in the last statement (the one
you use runST on). In other words, if you want to return a vector you
have to freeze it, so it's not mutable anymore.

If you still can't figure it out paste some complete example that
doesn't work.

silvio
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJP0Uu5AAoJEDLsP+zrbatWKFoP+wYdmAwO3aKPIibOydDwPlcu
GmwWLCDoylhBsA1swskPGZTlBevFFeS0kzDMAhZ2dtR18HHf0TVLFCL6mljgQGhu
YLsT8a2Y5eepPd7CC0wHD7qLH0t6ln/urRhWNnVEGryVHmsIDCBzuKBzopshaaOm
8awNeEbmZApki193r/YJ21Zsxidx4N2tSGCd712ka9Wr7l19RzBukonTy/wNCTtN
1sj54xCKap3MpnQe4L68nep6WjMovnwn5ucPWlouPP5N99/2umiEPDwX3y9moD/Q
VkbYe0HzZtvSX7JJaDM/hJ2dWKHsg5CLdO/aW7Uz3HttTy0/FmvwhxaNAzkmQimw
L4uakvyuw1EJuSAwB5XRfeUL6LDpka165jb8V8Iy2gjYg3aGMwf9VVmObjEAA93s
nvQd+iH1lDe38cbfz8dfQdTakDVYtFNnYL+kXIF1Z7DiS25IThtS0RJRH//E+CZg
MpOtW2LBfa3vwP9NqVryGTAhWFtWHXOtpXfCXOa0+pQNn1zHkTXtIDJ4XoT5qkmd
6GDwFyGfkPZO01qNMoXwj/wBz/eaSa4Vj0qb73jNdNH2MbJ13Ws9Jlp4jwcxbG4a
m/fYV0/6LmPEiV8H9+4cG8nhUP2ie2DJqo8tzdjiaZ7C7TEym9jd6gsljMQ8qiAG
Q7aAmMed/DBlY/Anh2xY
=X9CL
-END PGP SIGNATURE-



___
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] I don't understand how ST works

2012-06-08 Thread Nicu Ionita

Hi,

I created a gist with a minimal (still 111 lines) module:

https://gist.github.com/2898128

I still get the errors:

WhatsWrong.hs:53:5:
Couldn't match type `s' with `PrimState (ST s)'
  `s' is a rigid type variable bound by
  a type expected by the context: ST s [Move] at 
WhatsWrong.hs:48:21

In a stmt of a 'do' block: listMoves ml
In the second argument of `($)', namely
  `do { v - U.new maxMovesPerPos;
let ml = ...;
listMoves ml }'
In the expression:
  runST
  $ do { v - U.new maxMovesPerPos;
 let ml = ...;
 listMoves ml }

WhatsWrong.hs:65:44:
Couldn't match type `s' with `PrimState (ST s)'
  `s' is a rigid type variable bound by
  the type signature for nextPhaseOnlyCapts :: GenPhase s
  at WhatsWrong.hs:64:1
Expected type: U.MVector (PrimState (ST s)) Move
  Actual type: U.MVector s Move
In the return type of a call of `mlVec'
In the third argument of `genCapts', namely `(mlVec ml)'

Thanks,
Nicu

Am 08.06.2012 02:47, schrieb Silvio Frischknecht:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


Now comes my question: in the impure values there is always that
s. I was thinking that the whole structure should have s as a
parameter:

Yes


data MList s = MList { mlVec :: MVector s Move, mlNextPh :: MList
-

ST s (Maybe (MList s)) }

you probably meant:

 data MList s = MList { ... , mlNextPh :: Mlist s -  ... }

Now I'm not sure about your exact problem since the following compiles
for me.

 import Data.Vector
 import Data.Vector.Mutable
 import Control.Monad.ST

 type Move = ()
 data MList s = MList {
 mvVec :: MVector s Move,
 mlNextPh :: MList s -  ST s (Maybe (MList s)) }

 splitMove :: MList s -  ST s (Maybe (Move, MList s))
 splitMove ml = do
 m- unsafeRead (mvVec ml) 0
 undefined

Something you always have to watch out for when dealing with ST is not
to return something that depends on s in the last statement (the one
you use runST on). In other words, if you want to return a vector you
have to freeze it, so it's not mutable anymore.

If you still can't figure it out paste some complete example that
doesn't work.

silvio
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJP0Uu5AAoJEDLsP+zrbatWKFoP+wYdmAwO3aKPIibOydDwPlcu
GmwWLCDoylhBsA1swskPGZTlBevFFeS0kzDMAhZ2dtR18HHf0TVLFCL6mljgQGhu
YLsT8a2Y5eepPd7CC0wHD7qLH0t6ln/urRhWNnVEGryVHmsIDCBzuKBzopshaaOm
8awNeEbmZApki193r/YJ21Zsxidx4N2tSGCd712ka9Wr7l19RzBukonTy/wNCTtN
1sj54xCKap3MpnQe4L68nep6WjMovnwn5ucPWlouPP5N99/2umiEPDwX3y9moD/Q
VkbYe0HzZtvSX7JJaDM/hJ2dWKHsg5CLdO/aW7Uz3HttTy0/FmvwhxaNAzkmQimw
L4uakvyuw1EJuSAwB5XRfeUL6LDpka165jb8V8Iy2gjYg3aGMwf9VVmObjEAA93s
nvQd+iH1lDe38cbfz8dfQdTakDVYtFNnYL+kXIF1Z7DiS25IThtS0RJRH//E+CZg
MpOtW2LBfa3vwP9NqVryGTAhWFtWHXOtpXfCXOa0+pQNn1zHkTXtIDJ4XoT5qkmd
6GDwFyGfkPZO01qNMoXwj/wBz/eaSa4Vj0qb73jNdNH2MbJ13Ws9Jlp4jwcxbG4a
m/fYV0/6LmPEiV8H9+4cG8nhUP2ie2DJqo8tzdjiaZ7C7TEym9jd6gsljMQ8qiAG
Q7aAmMed/DBlY/Anh2xY
=X9CL
-END PGP SIGNATURE-



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


[Haskell-cafe] I don't understand how ST works

2012-06-07 Thread Nicu Ionita

Hi,

After trying the whole afternoon to make a program work using ST and 
mutable vectors, I must give up and ask for some help.


I have a pure function which generates a list of moves. But the whole 
thing should live in the ST monad, so:


 genMoves ... = runST $ do ...

Now, as I understand, I have a private universe (under runST) in which I 
can run impure code, from which nothing escapes to the outside.


Now in that universe I prepare succesively (and use later) a data 
structure which contains pure and impure values, for example:


 data MList = MList { mlVec :: MVector s Move, mlNextPh :: MList - ST 
s (Maybe MList) }


Now comes my question: in the impure values there is always that s. I 
was thinking that the whole structure should have s as a parameter:


 data MList s = MList { mlVec :: MVector s Move, mlNextPh :: MList - 
ST s (Maybe (MList s)) }


but then, when I define functions like:

 splitMove :: MList s - ST s (Maybe (Move, MList s))
 splitMove ml = do
  m - unsafeRead (mvVec ml) 0
  ...

I get this message:

Moves\MoveList.hs:217:28:
Couldn't match type `s' with `PrimState (ST s)'
  `s' is a rigid type variable bound by
  the type signature for
splitMove :: MList s - ST s (Maybe (Move, MList s))
  at Moves\MoveList.hs:210:1
Expected type: U.MVector (PrimState (ST s)) Move
 Actual type: U.MVector s Move
In the return type of a call of `mlVec'
In the first argument of `M.unsafeRead', namely `(mlVec ml)'

which really doesn't make sense, as the package primitive defines the 
instance:


instance PrimMonad (ST s) where
type PrimState (ST s) = s
primitive = ST
internal (ST p) = p

Should I do the structure agnostic of that s-state? (forall s. ...) This 
seems really unintuitive to me...


Anybody some hint?

Thanks,
Nicu

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


Re: [Haskell-cafe] Installation of the New Haskell Platform

2012-06-04 Thread Nicu Ionita

Am 04.06.2012 18:48, schrieb Brent Yorgey:

On Mon, Jun 04, 2012 at 11:04:36AM -0400, Victor Miller wrote:

Before I install it (on on Mac OS X Lion) is there anything, manually, that
I need to do in order to keep all of the cabal packages that I've
installed, or are the reinstalled automatically?

Neither.  If you install a new version of GHC, you must reinstall any
cabal packages you want, because they must be recompiled with the new
GHC.

Note that cabal-install does have a special command

   cabal install world

which (IIUC) is supposed to help automate this process, although I
can't vouch for it since I have never tried it.

-Brent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
I installed it on Windows 7 and then re-installed a lot of packages, it 
looks ok with exception of some warnings (-fglasgow-exts, for example). 
But the package stream-fusion could not compile, because it's cabal file 
has an illegal ghc option: -fno-method-sharing. I commented this out and 
then everything worked fine.

Nicu

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


Re: [Haskell-cafe] Problem with packet documentation generated by cabal on windows 7

2012-05-25 Thread Nicu Ionita

Am 25.05.2012 06:49, schrieb Magnus Therning:

On Fri, May 25, 2012 at 01:19:11AM +0200, Nicu Ionita wrote:

Hi cafe,

I have a problem with haddock documentation created when installing
new packages with cabal on windows.
The generated html files have all links in the form
j:\Users\...\doc\...\xxx.html, but firefox says, it cannot open that
link.
Actually all links should be prefixed by file:///.

I wonder if this is only on windows so and if there is a solution to
this. Is there a cabal or haddock flag for this?

It might help to know what version of haddock you have.

Here, on my Linux machine, all generated links are relative and hence
contain no 'http://' or 'file:///' prefix.

/M


I have Haskell Platform 2011.2.0.1 and I assumed that haddock comes with 
it. Now I checked the version - it is 2.9.2 and cabal info tells me that 
the last version is 2.10.0 and that I don't have the package installed (?).


Ok, now I see, haddock is that from the patform and I never install it 
with cabal...


Nicu

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


[Haskell-cafe] Problem with packet documentation generated by cabal on windows 7

2012-05-24 Thread Nicu Ionita

Hi cafe,

I have a problem with haddock documentation created when installing new 
packages with cabal on windows.
The generated html files have all links in the form 
j:\Users\...\doc\...\xxx.html, but firefox says, it cannot open that link.

Actually all links should be prefixed by file:///.

I wonder if this is only on windows so and if there is a solution to 
this. Is there a cabal or haddock flag for this?


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


Re: [Haskell-cafe] Problems with libgmp on Amazon Linux

2012-01-07 Thread Nicu Ionita

Am 07.01.2012 06:04, schrieb Yucheng Zhang:

On Sat, Jan 7, 2012 at 8:08 AM, Nicu Ionitanicu.ion...@acons.at  wrote:

It seemed to work pretty well, with some problems when configuring HP,
because although libgmp was already installed, it was not recognized. I
installed the newer version 5.0.2 (from sources) [4], did some tricks (cp
/usr/lib/lib/libgmp* /usr/lib), then configure worked and HP was built and
installed.

I think you should get the installed libgmp recognized, but not doing tricks
like this. It is no problem as a temporary solution, but you should always
try to make use of a package manager.


Loading package integer-gmp ...command line: can't load .so/.DLL for: gmp
(libgmp.so: cannot open shared object file: No such file or directory)

I have no experience with AWS, but it seems that you need to run a ldconfig
to rebuild the cache, since you installed libgmp just by copying into /usr/lib.

ldconfig -n /usr/bin


Thank you, a good point.

Just to let a trace for the posterity, here is what I did:

I now deleted libgmp* from /usr/lib (which I copied from /usr/lib/lib, 
where gmp did intstall, although I configured it with 
--prefix=/usr/lib), then ran:


sudo ldconfig /usr/lib/lib

which updated also the ld cache, and then I defined (in .bash_profile)

LD_LIBRARY_PATH=/usr/lib/lib

After a new login everything could be installed (I installed aws and 
criterion, after which half of Hackage was on my machine ;-) This 
installation point of gmp is a bit odd, but I don't want now to find out 
why the gmp intallation procedure doesn't honor --prefix.


After this I made an AMI (image) of it, which could be used as a start 
point for further installations.


I did not test the installation extesively yet, but by so many 
succefully installed packages, I'm confident that everything is ok. Next 
days I'll play with it.


By the way, I let gmp 5.0.2 there, it looks that HP 2011.04 likes it.

Nicu

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


Re: [Haskell-cafe] Problems with libgmp on Amazon Linux

2012-01-07 Thread Nicu Ionita

Am 07.01.2012 20:01, schrieb Nabil Alsharif:

Ahh your main issue is that --prefix should be /usr not /usr/lib
It would be best to reinstall libgmp with the correct prefix.

Oh, thanks, I will try this.

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


[Haskell-cafe] Problems with libgmp on Amazon Linux

2012-01-06 Thread Nicu Ionita

Hello,

I saw [1] there is a lot of activity in the Haskell community regarding 
Amazon Web Services (AWS). As they allow an easy start [2], I decided to 
giv it a try and followed the procedure published by JP Moresmau [3] to 
install the Haskell Plattform on Amazon Linux (a minimal linux 
distribution maintained by Amazon), but with the new Haskell Platform, 
2011.4.0.0 (and ghc 7.0.4).


It seemed to work pretty well, with some problems when configuring HP, 
because although libgmp was already installed, it was not recognized. I 
installed the newer version 5.0.2 (from sources) [4], did some tricks 
(cp /usr/lib/lib/libgmp* /usr/lib), then configure worked and HP was 
built and installed.


But then later I wanted to install the aws package (cabal install aws) 
and then the vector package could not be installed - again because of 
libgmp! Here are the last messages, followed by a ls of /usr/lib, where 
it's clear that the libraries are there:


[ 4 of 30] Compiling Data.Vector.Internal.Check ( 
Data/Vector/Internal/Check.hs, dist/build/Data/Vector/Internal/Check.o )
[ 5 of 30] Compiling Data.Vector.Fusion.Stream.Monadic ( 
Data/Vector/Fusion/Stream/Monadic.hs, 
dist/build/Data/Vector/Fusion/Stream/Monadic.o )

Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... command line: can't load .so/.DLL for: 
gmp (libgmp.so: cannot open shared object file: No such file or directory)

cabal: Error: some packages failed to install:
vector-0.9.1 failed during the building phase. The exception was:
ExitFailure 1
[ec2-user@ip-10-234-49-92 ~]$ ls -l /usr/lib/libgmp*
-rw-r--r-- 1 root root 1175336 Jan  4 22:21 /usr/lib/libgmp.a
-rwxr-xr-x 1 root root 915 Jan  4 22:21 /usr/lib/libgmp.la
-rwxr-xr-x 1 root root  484673 Jan  4 22:21 /usr/lib/libgmp.so
-rwxr-xr-x 1 root root  484673 Jan  4 22:21 /usr/lib/libgmp.so.10
-rwxr-xr-x 1 root root  484673 Jan  4 22:21 /usr/lib/libgmp.so.10.0.2
[ec2-user@ip-10-234-49-92 ~]$

I'm just asking here hoping that someone had already solved this 
problem. Or perhaps someone can explain how cabal ensures that a library 
is there. The error message - as it is - is meaningless, as the file 
exists and has read permissions for everybody.


Thank you,
Nicu

[1] 
http://www.reddit.com/r/haskell/comments/o1u2g/deploying_a_haskell_app_to_amazon_ec2/

[2] https://aws.amazon.com/free/
[3] 
http://jpmoresmau.blogspot.com/2011/04/install-ghc7-and-yesod-on-amazon-linux.html

[4] ftp://ftp.gnu.org/gnu/gmp/

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


Re: [Haskell-cafe] Comparison Haskell, Java, C and LISP

2011-10-18 Thread Nicu Ionita

Am 18.10.2011 18:53, schrieb Stephen Tetley:

Haskell has no support for reflection whatsoever.

It can support compile time meta-programming with Template Haskell.

Reflection itself might be antagonistic to functional programming, I
suspect it is at odds with referential transparency. Most of the work
on reflection seemed based around Lisp / Scheme - Christian Queinnec's
reflective interpreter in Lisp in Small Pieces uses an awful lot of
set! 

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

But is (delimited) continuation not a kind of reflection?
Nicu

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


Re: [Haskell-cafe] Much faster complex monad stack based on CPS state

2011-09-28 Thread Nicu Ionita

Am 28.09.2011 14:05, schrieb Yves Parès:

Interesting, so what have you used to get that speedup?
A monad stack of ContT and State (*)? Just the Cont monad?

This is a module with a state monad transformer that I used before (the 
name STPlus is misleading - and sorry for the long email):


{-# LANGUAGE RankNTypes, MultiParamTypeClasses, FlexibleInstances #-}

module Search.SearchMonad (
STPlus,
return, (=),
get, put, gets, modify,
lift, liftIO,
runSearch, execSearch
) where

import Control.Monad
import Control.Monad.State hiding (lift, gets, modify)

newtype STPlus s m a = STPlus { runSTPlus :: s - m (a, s) }
{-# INLINE runSTPlus #-}

instance Monad m = Monad (STPlus s m) where
{-# INLINE return #-}
return v = STPlus (\s - return (v, s))
{-# INLINE (=) #-}
(=)= bindSTPlus

{-# INLINE bindSTPlus #-}
bindSTPlus :: Monad m = STPlus s m a - (a - STPlus s m b) - STPlus s m b
bindSTPlus ms f = STPlus $ \s - case runSTPlus ms s of
 m - m = \(v', s') - case f v' of
fv - 
runSTPlus fv s'


instance Monad m = MonadState s (STPlus s m) where
{-# INLINE get #-}
get   = STPlus $ \s - return (s,  s)
{-# INLINE put #-}
put s = STPlus $ \_ - return ((), s)

instance MonadIO m = MonadIO (STPlus s m) where
{-# INLINE liftIO #-}
liftIO = lift . liftIO

runSearch :: Monad m = STPlus s m a - s - m (a, s)
runSearch = runSTPlus

execSearch ms s = liftM snd $ runSearch ms s

{-# INLINE lift #-}
lift :: Monad m = m a - STPlus s m a
lift m = STPlus $ \s - m = \v - return (v, s)

{-# INLINE gets #-}
gets :: Monad m = (s - a) - STPlus s m a
-- gets f = STPlus $ \s - return (f s, s)
gets f = STPlus $ \s - case f s of fs - return (fs, s)

{-# INLINE modify #-}
modify :: Monad m = (s - s) - STPlus s m ()
modify f = STPlus $ \s - case f s of fs - return ((), fs)

And this is how the module looks now:

{-# LANGUAGE RankNTypes, MultiParamTypeClasses, FlexibleInstances #-}

module Search.SearchMonadCPS (
STPlus,
return, (=),
get, put, gets, modify,
lift, liftIO,
runSearch, execSearch
) where

import Control.Monad
import Control.Monad.State hiding (lift, gets, modify)

newtype STPlus r s m a = STPlus { runSTPlus :: s - (a - s - m r) - m r }

instance Monad (STPlus r s m) where
return a = STPlus $ \s k - k a s
c = f  = STPlus $ \s0 k - runSTPlus c s0 $ \a s1 - runSTPlus (f 
a) s1 k


instance MonadState s (STPlus r s m) where
get   = STPlus $ \s k - k s  s
put s = STPlus $ \_ k - k () s

instance MonadIO m = MonadIO (STPlus r s m) where
{-# INLINE liftIO #-}
liftIO = lift . liftIO

runSearch :: Monad m = STPlus (a, s) s m a - s - m (a, s)
runSearch c s = runSTPlus c s $ \a s0 - return (a, s0)

execSearch ms s = liftM snd $ runSearch ms s

{-# INLINE lift #-}
lift :: Monad m = m a - STPlus r s m a
lift m = STPlus $ \s k - m = \a - k a s

{-# INLINE gets #-}
gets :: Monad m = (s - a) - STPlus r s m a
gets f = STPlus $ \s k - k (f s) s

{-# INLINE modify #-}
modify :: Monad m = (s - s) - STPlus r s m ()
modify f = STPlus $ \s k - k () (f s)

And then I have (in different modules):

Client code (starting an PV search to a given depth):

type CtxIO = ReaderT Context IO

bestMoveCont :: Int - MyState - Maybe Int - [Move] - [Move] - CtxIO 
IterResult

bestMoveCont ... = do
 ...
 ((sc, path, rmvsf), statf) - runSearch (alphaBeta abc) stati
 ...

Search framework:

class Monad m = Node m where
staticVal :: m Int  -- static evaluation of a node
materVal  :: m Int  -- material evaluation (for prune purpose)
genEdges :: Int - Int - Bool - m ([Move], [Move])  -- generate 
all legal edges

genTactEdges :: m [Move]  -- generate all edges in tactical positions
...
type Search m a = forall r. STPlus r PVState m a

alphaBeta :: Node m = ABControl - m (Int, [Move], [Move])
alphaBeta abc = do
let !d = maxdepth abc
rmvs = Alt $ rootmvs abc
lpv  = Seq $ lastpv abc
searchReduced a b = pvRootSearch a   b  d lpv rmvs True
searchFull= pvRootSearch salpha0 sbeta0 d lpv rmvs False
r - if useAspirWin
...
pvRootSearch :: Node m = Int - Int - Int - Seq Move - Alt Move - Bool
 - Search m (Int, Seq Move, Alt Move)
...

And then the chess specific implementation of the game state in another 
module:


type Game r m = STPlus r MyState m
...
instance CtxMon m = Node (Game r m) where
staticVal = staticVal0
materVal  = materVal0
genEdges = genMoves
...
genMoves :: CtxMon m = Int - Int - Bool - Game r m ([Move], [Move])
genMoves depth absdp pv = do

Nicu

(*) If so, were you using the strict version of State?

Would it be possible to see the differences between the 2 versions of 
you code?


2011/9/27 Nicu Ionita nicu.ion...@acons.at mailto:nicu.ion...@acons.at

Hello list,

Starting from this emails
(http://web.archiveorange.com/archive/v

Re: [Haskell-cafe] Much faster complex monad stack based on CPS state

2011-09-28 Thread Nicu Ionita

Am 28.09.2011 02:35, schrieb Ryan Ingram:
My guess is that Cont plays really nicely with GHC's inliner, so 
things that end up looking like


 return x = \y - ...

get optimized really well

return x = f
-- inline =
= ContState $ \s0 k - runCS (return x) s0 $ \a s1 - runCS (f a) s1 k
-- inline return
= ContState $ \s0 k - runCS (ContState $ \s2 k2 - k2 x s2) s0 $ 
\a s1 - runCS (f a) s1 k

-- runCS record selector
= ContState $ \s0 k - (\s2 k2 - k2 x s2) s0 $ \a s1 - runCS (f 
a) s1 k

-- beta
= ContState $ \s0 k - (\k2 - k2 x s0) $ \a s1 - runCS (f a) s1 k
-- beta
= ContState $ \s0 k - (\a s1 - runCS (f a) s1 k) x s0
-- beta
= ContState $ \s0 k - runCS (f x) s0 k

and then further inlining of f can take place.


I was even thinking - and this would have been the next idea to try if I 
couldn't get your example code to run so fast - to define some rules for 
the state monad (transformer) to fuse such expressions like


m = f = g = ...

or even

modify f = modify g = modify (g . f)

and perhaps other variations, so that it would perhaps end up in some 
nice combination of f and g, avoiding the intermediate tuples, hopefully 
with better performance. But then I did not follow it, and I want to 
concentrate on further improvements with the new code. The way is still 
long, because the top engines (written in C or C++) can do about 10 mil 
nps on my machine :-)


Nicu

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


[Haskell-cafe] Much faster complex monad stack based on CPS state

2011-09-26 Thread Nicu Ionita

Hello list,

Starting from this emails 
(http://web.archiveorange.com/archive/v/nDNOvSM4JT3GJRSjOm9P) I could 
refactor my code (a UCI chess engine, with complex functions, in which 
the search has a complex monad stack) to run twice as fast as with even 
some hand unroled state transformer! So from 23-24 kilo nodes per second 
it does now 45 to 50 kNps! And it looks like there is still some 
improvement room (I have to play a little bit with strictness 
annotations and so on).


(Previously I tried specializations, then I removed a lot of 
polimorphism, but nothing helped, it was like hitting a wall.)


Even more amazingly is that I could program it although I cannot really 
understand the Cont  ContT, but just taking the code example from Ryan 
Ingram (newtype ContState r s a = ...) and looking a bit at the code 
from ContT (from the transformers library), and after fixing some 
compilation errors, it worked and was so fast.


I wonder why the transformers library does not use this kind of state 
monad definition. Or does it, and what I got is just because of the 
unrolling? Are there monad (transformers) libraries which are faster? I 
saw the library kan-extensions but I did not understand (yet) how to use it.


Nicu

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


[Haskell-cafe] SPECIALIZE in the presence of constraints

2011-09-25 Thread Nicu Ionita

Hallo List,

I can't understand how pragma SPECIALIZE works in the presence of 
constraints.


I have 2 modules, one which defines a general search framework, and one 
which implements it in a concrete context. The general module defines 
functions like:


{-# SPECIALIZE pvQSearch :: Node (Game m) Move Int = Int - Int - Int 
- Search (Game m) Move Int Int #-}

pvQSearch :: Node m e s = s - s - Int - Search m e s s
pvQSearch a b c = do ...

while the implementation uses concrete data types Move and Int (for e 
and s respectively) and defines instances and other types (like the 
polimorphic type Game m, where m is a monad).


Node m e s is a class and the instance Node (Game m) Move Int is defined 
in the implementation module. From outside this construct is used by 
calling a generic search function, but giving parameters which match the 
implementation (i.e. with Move and Int for e and s, for example).


Now what I don't understand:

1. how can the compiler (here ghc) know which function to expose as the 
correct generic search function? There must be two search functions 
generated, one generic and its specialization. Does the module export 
both and later the linker chooses the correct one, when the client 
module is known?


2. how can I know that the specialization is really used? When I have 
constraints, will the specializations be generated in the assumption 
that the constraint is matched? When will be this match checked?


My problem is that, with or without specializations, the performance of 
the code is the same - so I doubt the specializations are used.


Thanks,

Nicu

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


Re: [Haskell-cafe] Building Haskell Platform natively for 64bit Windows

2011-06-09 Thread Nicu Ionita

Am 09.06.2011 19:44, schrieb Andrew Coppin:

On 09/06/2011 06:54 AM, Scott Lawrence wrote:

On 06/09/2011 01:47 AM, Jason Dagit wrote:

Have you checked this by looking at the generated assembly?  I
generated some assembly from GHC on windows.  Here is what it looks
ilke:
http://hpaste.org/47610

My assembly-fu is not strong enough to tell if it's using 64bit 
instructions.



It would appear to be 32-bit. (pushl instead of pushq  no instances of
aligning to 8-byte boundaries)


The general register naming scheme on x86 is:

  AL, AH: 8 bits
  AX: 16 bits
  EAX: 32 bits
  RAX: 64 bits

There's a lot of code there, but from what I can see, it's all 
operating on 32-bit registers. So I'd say this is 32-bit code.


On the other hand, I still think it would be worth actually 
benchmarking this stuff to see how much difference it makes. Wouldn't 
surprise me if the CPU designers did some clever trickery with 
pipelining and superscalar execution to make two adjacent 32-bit 
instructions execute the same way as a single 64-bit instruction would...


(I've seen various sources claim that running software in 64-bit mode 
only gives you a 2% speedup. Then again, they presumably aren't 
testing with chess software which heavily utilises explicit 64-bit 
operations.)


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
For a chess engine this is for sure not true. I guess that this is one 
of very few domains where it really matters! The most (basic) operations 
with bitboards are anding, oring, xoring, shifting and (for magic 
bitboards) multiplying 64 bits values. When using 32 bits you need for 
some of these more then double time to achieve the same.


I was wondering if there is a possibility to support 64 bit native codes 
without other stuff (calling conventions, win64 specific system calls 
etc). This could be perhaps a first step to full 64 bit support. But 
from the code of ghc I could not understand what this would mean.


Nicu

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


Re: [Haskell-cafe] Building Haskell Platform natively for 64bit Windows

2011-06-07 Thread Nicu Ionita

Am 07.06.2011 19:37, schrieb Andrew Coppin:

On 06/06/2011 09:34 PM, Nicu Ionita wrote:


Hi,

Just to double check: that means, today it's not possible to generate 64
bit operations under Windows, including bit level .., .|. a.s.o. (from
Data.Bits), and this situation will stay like this for a while.

I'm asking this because I'm currently writing a pure Haskell chess
engine based on bitboards. The bitboards are 64 bit wide and the basic
operations are critical for speed, which is always critical in chess
engines.

Then it looks I'll have to implement these operations in C and use FFI
to link them.


No, 64-bit integer operations will /work/ just fine, regardless of 
what platform you're on. Whether it will take advantage of 64-bit 
operations at the machine-code level is another matter entirely.


I'm not especially sure, but I think even in 32-bit mode, the x86 line 
of processors supports performing 64-bit operations via MMX, SSE or 
similar. Whether GHC is using that, I couldn't tell you.


I suppose the ultimate answer is: Benchmark it, and see how fast it is.

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


Yes, I was a little bit unclear, I wanted to say: the generated code 
does not use the 64 bit instructions (i.e. 1 instruction for .., for 
example). Of course, it works, but I suppose, much slower then it could 
(3-4 times, for that part?)


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


Re: [Haskell-cafe] Building Haskell Platform natively for 64bit Windows

2011-06-06 Thread Nicu Ionita

Am 23.05.2011 13:32, schrieb Simon Marlow:

On 18/05/2011 19:22, Jason Dagit wrote:
On Wed, May 18, 2011 at 2:50 AM, John Sneerjohnsn...@operamail.com  
wrote:

Hello all,

  I know it is not probably good question to this list, but anyway,
  could anyone point me to some more detailed how to where is
  described building of Haskell Platform natively to 64bit Windows?


If you figure out how to do this, I would like to know as well.  I
could also benefit from 64bit Haskell on windows.


There is no port of GHC to 64-bit Windows yet.  Various people have 
expressed an interest in having one, but it is a significant chunk of 
work to implement (plus extra work to maintain and build 
distributions), so we don't have any plans to do it in the short term.


You can track progress (or lack thereof) by adding your email to the 
CC on the ticket:


http://hackage.haskell.org/trac/ghc/ticket/1884

If you want to help out, join cvs-...@haskell.org and we can help with 
pointers to what needs to be done.


Cheers,
Simon

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


Hi,

Just to double check: that means, today it's not possible to generate 64 
bit operations under Windows, including bit level .., .|. a.s.o. (from 
Data.Bits), and this situation will stay like this for a while.


I'm asking this because I'm currently writing a pure Haskell chess 
engine based on bitboards. The bitboards are 64 bit wide and the basic 
operations are critical for speed, which is always critical in chess 
engines.


Then it looks I'll have to implement these operations in C and use FFI 
to link them.


Nicu

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


AW: [Haskell-cafe] ICFP contest

2009-06-23 Thread Nicu Ionita
Last year the problem was not too bad, but I failed because I didn't have a
working linux installation and the live cd started on my notebook in the
first day, but in the second no more (you had to deliver a linux binary).

Two years ago there was no need to deliver a binary, but I did not have any
idea how to start.

This year I'll try again (in Haskell, of course), but you're right, alone it
can be very hard.

Nicu Ionita


 -Ursprüngliche Nachricht-
 Von: haskell-cafe-boun...@haskell.org 
 [mailto:haskell-cafe-boun...@haskell.org] Im Auftrag von 
 Miguel Mitrofanov
 Gesendet: Dienstag, 23. Juni 2009 21:27
 An: Rafael Gustavo da Cunha Pereira Pinto
 Cc: Haskell Café
 Betreff: Re: [Haskell-cafe] ICFP contest
 
 
 Well, I can make a bit more concrete prediction.
 
 I'll download the problem, take a look, try for a while, discover,  
 that it's too hard to be cracked at once, and lose interest.
 
 That sounds like a reason why I'm not participating.
 
 On 23 Jun 2009, at 22:49, Rafael Gustavo da Cunha Pereira Pinto wrote:
 
  Hi,
 
  The good folks here are really quiet about the ICFP Contest. Is
  anyone participating this year?
 
  As in the previous four years, I will probably download the problem,
  take a look, and try for a while... Having a family don't allow me  
  to go much further, especially when teaming up with myself!
 
  Best regards,
 
 
  Rafael Gustavo da Cunha Pereira Pinto
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org 
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org 
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 


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


[Haskell-cafe] Basic problem in Haskell language design?

2009-03-01 Thread Nicu Ionita
Hi,

Today I found the following problem when writing a simple function:

 -- Whole info from a word8 list to moves
 movesFromWord8s :: [Word8] - [Move]
 movesFromWord8s (f:t:ws) = (f, t) : movesFromWord8s ws
 moverFromWord8s _ = []

Here I made a small typo in the second equation, writing mover... instead
of moves... for the name of the declared function. Of course this is an
error, because I have non-exhaustive patterns in the function
movesFromWord8s. But the compiler (here GHC 6.8.2 on WinXP) has in principle
no chance to detect this mistake, I saw it only in QuickCheck (aka at
run-time).

I think this is a basic problem with the language design. In small programs
it's not so bad, but in large ones this could be. What do you think about
it? Are there possible solutions or workarounds?

Nicu Ionita


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


AW: [Haskell-cafe] Re: Basic problem in Haskell language design?

2009-03-01 Thread Nicu Ionita
Ok, thanks, compiling from Eclipse I totally forgot to check the compiler
flags.

Nicu Ionita


 -Ursprüngliche Nachricht-
 Von: haskell-cafe-boun...@haskell.org 
 [mailto:haskell-cafe-boun...@haskell.org] Im Auftrag von Stuart Cook
 Gesendet: Sonntag, 1. März 2009 14:45
 An: haskell-cafe@haskell.org
 Betreff: Re: [Haskell-cafe] Re: Basic problem in Haskell 
 language design?
 
 
 On Mon, Mar 2, 2009 at 12:35 AM, Achim Schneider 
 bars...@web.de wrote:
  -Wall? The number of -W options enabled should scale (at least) 
  linearly with code size.
 
 To make this a little more clear:
 
 You should probably be using the -Wall compiler option, which 
 will produce a message for code constructs that the compiler 
 finds suspicious.
 
 In your case you should see three relevant warnings:
 
 1. moverFromWord8s is defined but not used
 2. moverFromWord8s has no explicit type signature
 3. movesFromWord8s has a non-exhaustive pattern match
 
 
 Stuart
 ___
 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


AW: [Haskell-cafe] Something like optimistic evaluation

2008-04-29 Thread Nicu Ionita
I don't know if this would be worth, but theoretically one could go on and
evaluate those thunks that:
 
a) would be evaluated anyway (after the current IO operation have been
completed)
b) do not depend on the result of the current operation
 
And, of course, the GC could work in this time also.
 
Nicu

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag von Brent Yorgey
Gesendet: Dienstag, 29. April 2008 16:42
An: Daniil Elovkov
Cc: haskell-cafe@haskell.org
Betreff: Re: [Haskell-cafe] Something like optimistic evaluation



On Mon, Apr 28, 2008 at 6:09 PM, Daniil Elovkov
[EMAIL PROTECTED] wrote:


Hello

Somewhat on the topic of optimistic evaluation, I've just thought of another
way to evaluate thunks.

When the program is about to block on some IO, what if we start a thread to
evaluate (any) unevaluated thunks. We'll have additional system thread, but
the blocked one will not actually consume any processor time.

This would take place only when the program is compiled as threaded and run
with -N k, k1.

The RTS knows at least about some operations that will block, those which IO
operations are implemented with. for example. It could merely start a
process of evaluating any (or something more clever) outstanding thunks
right before going into one of those operations and stop it when it's back.

Of course, it's not like optimistic evaluation because we don't avoid
creating thunks. But in a sense it's similar. It could also be compared with
incremental garbage collection :)

Has something like that been done, discussed?



This sounds like it could be helpful in certain circumstances, but in many
cases it could probably lead to unpredictable (and uncontrollable!) memory
usage.  I could imagine a situation where my program is running along just
fine, and then one day it takes a long time to do a read from the network
due to latency or whatever, and suddenly memory usage shoots through the
roof, due to evaluation of some infinite (or even just very large) data
structure.  

-Brent


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


[Haskell-cafe] Need help with Parsec

2008-01-20 Thread Nicu Ionita
Hi,

I'm playing since a few hours with Parsec and trying to write a small html
(fragment) parser, but I'm stuck in a point which I really can't understand.

The problem seem to be either in parseProperCont or in closing (see code
below). It looks like closing does not work (but it is a very simple
function!) or (also hard to believe) function try from Parsec has some
problems.

Anyway I get this answer:

Prelude ParseSHtml pf parseHtmlFrg ptest.txt
Left ptest.txt (line 5, column 2):
unexpected /
expecting element name

when I'm parsing this file:

div id=normtext
one line with breakbr /
another line br /br /
Mail: a href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/a
/div

with this code (sorry for the longer mail):

import Text.ParserCombinators.Parsec hiding (label)
import Text.XHtml.Strict

-- Helper function: parse a string up to one of the given chars
upTo :: [Char] - Parser [Char]
upTo ds = many1 (noneOf ds)

parseHtmlFrg :: Parser Html
parseHtmlFrg = do many space
  choice [parseElem, parseText]
   ? html fragment

parseElem :: Parser Html
parseElem = do en - parseElTag
   many1 space
   (ats, cnt) - restElem en
   return $ compElem en cnt ! ats
? html element

-- Compose a html element from tag name and content
compElem en cnt = if isNoHtml cnt then itag en else tag en cnt

parseElTag :: Parser String
parseElTag = do char ''
en - elemName
return en
 ? element tag

elemName :: Parser String
elemName = many1 lower ? element name

restElem :: String - Parser ([HtmlAttr], Html)
restElem nm = do ats - parseAttList
 ht - (restElNoCont | restElCont nm)
 return (ats, ht)
  ? ( or / to close the tag  ++ nm)

-- Rest element with no content
restElNoCont = do char '/'
  char ''
  return noHtml
   ? /

-- Rest element with content
restElCont nm = do char ''
   many space
   els - parseProperCont nm
   return $ concatHtml els
? element with content

-- Parse closing tag or proper content(s)
parseProperCont :: String - Parser [Html]
parseProperCont nm = try (do closing nm
 return []
  )
 | (do h - parseHtmlFrg
 hs - parseProperCont nm
 return (h:hs)
  )
 -- | return []
 ? proper element content

closing nm = do char ''
char '/'
nm1 - elemName
char ''
if nm1 == nm
   then return ()
   else fail $ nm ++ , encountered  ++ nm1
 ? (closing of  ++ nm)

-- Parse a html attribute
parseAttr :: Parser HtmlAttr
parseAttr = do at - many1 lower
   char '='
   va - parseQuote
   many space
   return $ strAttr at va
? Attribut
parseAttList = many1 parseAttr | return [] ? attribute list

-- Parse a quoted string
parseQuote :: Parser String
parseQuote = do char ''
cs - upTo ['']
char ''
return cs

-- Parse a text element
parseText :: Parser Html
parseText = do s - upTo 
   return (stringToHtml s)
? some text

-- For tests:
pf p file = parseFromFile p file

Nicu

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


[Haskell-cafe] ST Monad - what's wrong?

2007-12-09 Thread Nicu Ionita
Hi,

I'm trying to use the ST monad in order to turn an almost pure function into
a pure one: reading a precalculated list of primes into a prime set. But the
following code brings an error:

 primes :: Set Integer
 primes = runST $ getPrimes primes10h7.txt

 getPrimes :: String - (forall s. ST s (Set Integer))
 getPrimes file =
 do cont - unsafeIOToST (readFile file)
let set = fromList $ map read $ lines cont
return set

And here is the error:

Couldn't match expected type `forall s. ST s a'
against inferred type `ST s (Set Integer)'
In the second argument of `($)', namely
`getPrimes primes10h7.txt'
In the expression: runST $ (getPrimes primes10h7.txt)
In the definition of `primes':
primes = runST $ (getPrimes primes10h7.txt)

Compiled with GHC 6.6.1 with extensions activated.

Nicu

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


[Haskell-cafe] AW: ST Monad - what's wrong?

2007-12-09 Thread Nicu Ionita
Ok, solved, the use of ($) was the problem.

I changed it

 primes :: Set Integer
 primes = runST (getPrimes primes10h7.txt)

and it compiles (and works too).

Nicu


 -Ursprüngliche Nachricht-
 Von: Nicu Ionita [mailto:[EMAIL PROTECTED] 
 Gesendet: Sonntag, 9. Dezember 2007 12:12
 An: 'haskell-cafe@haskell.org'
 Betreff: ST Monad - what's wrong?
 
 
 Hi,
 
 I'm trying to use the ST monad in order to turn an almost 
 pure function into a pure one: reading a precalculated list 
 of primes into a prime set. But the following code brings an error:
 
  primes :: Set Integer
  primes = runST $ getPrimes primes10h7.txt
 
  getPrimes :: String - (forall s. ST s (Set Integer)) 
 getPrimes file =
  do cont - unsafeIOToST (readFile file)
 let set = fromList $ map read $ lines cont
 return set
 
 And here is the error:
 
 Couldn't match expected type `forall s. ST s a'
 against inferred type `ST s (Set Integer)'
 In the second argument of `($)', namely
 `getPrimes primes10h7.txt'
 In the expression: runST $ (getPrimes primes10h7.txt)
 In the definition of `primes':
 primes = runST $ (getPrimes primes10h7.txt)
 
 Compiled with GHC 6.6.1 with extensions activated.
 
 Nicu
 

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