[Haskell-cafe] Re: Newbie on instance of Monad

2008-11-02 Thread Mauricio

Hi,

After a lot of thinking, I can't get what I
am doing wrong in this code:
(...)
data ( RandomGen g ) = RandomMonad g a = RandomMonad (g - a)


RandomGen g is considered the constraint for the application of 
RandomMonad constructor, but GHC does not conclude that every value of 
(RandomMonad g a) fulfills this constraint. Actually, 'undefined' is 
available for any 'g'.


you need to make (RandomGen g) a constraint of the instance:

instance RandomGen g = Monad (RandomMonad g) where


Nice. I wasn't so wrong as I though :)

I didn't understand why can't the compiler deduce
that g is always going to be of type RandomGen. Even
if I use 'undefined', it has to be a RandomGen undefined.


Btw. RandomMonad looks like Control.Monad.Reader.


You are right, I'll try that instead so I learn a little
bit more. But I can't understand this syntax:

class (Monad m) = MonadReader r m | m - r where

What is the '|' doing there? I'll post that in a new thread
since it's a different question.

Thanks,
Maurício

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


[Haskell-cafe] Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Mauricio

Hi,

I've reading Control.Monad.Reader source code and
arrived here:

class (Monad m) = MonadReader r m | m - r where

I can't understand that syntax. Since this is not a
'data' line, what is the '|' supposed mean?

Thanks,
Maurício

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


Re: [Haskell-cafe] Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Andrew Coppin

Mauricio wrote:

Hi,

I've reading Control.Monad.Reader source code and
arrived here:

class (Monad m) = MonadReader r m | m - r where

I can't understand that syntax. Since this is not a
'data' line, what is the '|' supposed mean?


It's called a functional dependency. This is not part of the 
Haskell-98 language standard; check the GHC manual.

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


[Haskell-cafe] Need help with VXML again (fun deps and forall types)

2008-11-02 Thread Marc Weber
Some time I've announced that I'm working on VXML, a validating xml
library.

The use case which makes trouble is elem+ (one or more)

!ELEMENT root (a|b|(c,d+))*

This example is encoded in this way:


root - St 1

 id :1
   endable : True
   a - St 1
   b - St 1
   c - St 12


 id :11
   endable : True
   (a|b|c) - St 1
   d - St 11

 id :12
   endable : False
   d - St 11

to be read as:
When creating a new root element start with state 1, then expect one of
a,b,c subelemnts.

If subelement c is added continue with state 12. The element may not be 
finalized
(endable false because a d is expected). Following that we end in a
loop at state 11 which is endable when only adding more d subelemnts.

in VXML it looks like this
  print $ fStr $ runRoot $ vdo
  -- forceElements
  c e
  d e -- first,  result has state 12A
  d e -- second, result has state 11X
  d e -- thrd,   result has state 11 
  d e -- fourth, result has state 11Y
  -- ... 

Now I'd like to do something convinient such as
  foldr1 () print $ [1..10]

I've called the corresponding function in VXML vxmlgtgt because it can
be used like a monad and even do notation is supported using the vdo cpp
macro rebinding (), (=) and return.
Obviously I can only use foldr from X up to Y because A has a different
return type.

If you download the latest version of the library 
  (git clone git://mawercer.de/vxml; git checkout fc160ab  # is master branch )

you see that it actually works quite fine

  -- helper function: 
  vxmlSeqPlus_ (f,fl) = f `vxmlgtgt`  (foldr1 vxmlgtgt fl)

  -- usage example from testSimple.hs, note that both (d e) have different types
  vxmlSeqPlus_ ((d e), replicate 9 (d e))

d is actually a function creating the d element requiring a
function as first argument which adds attrubutes and subelemnts (e is a
nop here)

This all makes d having a type which looks rather complicated:
el*: the result type (String only in the current implementation)

  data VXML st el_
st2 el2_
st3 el3_ a
= VXML {
runVVXML :: 
(PT st el_ - PT st2 el2_)  -- [1]
  - (a, PT st el_ - PT st3 el3_)  -- [2]
}
[1] : st - st2 : The function which is passed
[2] : st - st3 : The type of function which is returned
  taking a function modyfiying the parent and adding d 
resulting in st3
  (st3 is either State12 in A, or State11 in Y talking about 
the example given above)

Its even getting more interesting now:
Because I'd like to use different result types (String, ByteString, ...)
I've used a type var to represent that type. I've called them el el2 el3
etc. When finally creating the document by using runRoot the result
types propagates through the xml tree by functional dependencies.

An example is the AddElT class which actually does add a subelement:

  class AddElT est el_ 
   estc elc_
   est2 el2_
  | est estc - est2  -- result state is determined by parent and  
child element state
  , est est2 estc el2_ - el_  -- the result type of child and parent 
privious sibling are determined by the el2_ return type and the element states
  , est est2 estc el2_ - elc_
  where
addElT :: PT est el_ - PT estc elc_ - PT est2 el2_

The instance has constraints like this determining el_ elc_ and st2
  instance (
  , DetermineElAddEl 
  (NYV (Element elType AttrsOk st hchs)) el2
  cest2 elc2
  (NYV (Element elType AttrsOk st2 HTrue)) el3

  , Consume st (Elem celType) st2
  [..]
) =  AddElT [..]

Determining states form leafs to the root then propagating String or
ByteString result type form the root to the leaf depending on states
works fine until I start trying to use shortcut for the foldr1 example
above.

Instead of 
  vxmlSeqPlus_ ((d e), replicate 9 (d e))

I'd like to write this. Of course the lamba here is polymorphic because
it must return State 12 the first time and State 11 in the following
cases.
  vxmlMapSeqPlus_ (\_ - d e) [1..10] -- Ex I 

It's implementation is straight forward:
vxmlMapSeqPlus_ f (x:xs) = vxmlSeqPlus_ (f x, map f xs)
vxmlMapSeqPlus_ _ [] = error vxmlSeqPlus has been called with empty list

My attempt to assign a type looks like this:
  vxmlMapSeqPlus_ :: ( VXMLMonad m  st el  st2 el2  st3 el3  st3 el3
 , VXMLMonad m  st el  st3 el3  st3 el3  st3 el3
 ) = (forall st' elA st'' elB . t - m  st el  st' elA  
st'' elB ())
- [t]
- m st el st2 el2 st3 el3 ()
  vxmlMapSeqPlus_ f (x:xs) = vxmlSeqPlus_ (f x , map f xs)
  vxmlMapSeqPlus_ _ [] = error vxmlSeqPlus has been called with empty list


  where

  class VXMLMonad m  st el_  st2 el2_  st3 el3_  st4 el4_ where
vxmlgtgt ::  m st el_  st2 el2_  st3 el3_  a
  - m st el_  st3 el3_  st4 el4_  b
   

[Haskell-cafe] Re: [Haskell] ANNOUNCE: RefSerialize-0.2.1

2008-11-02 Thread Alberto G. Corona
I uploadad 
RefSerializehttp://hackage.haskell.org/cgi-bin/hackage-scripts/package/RefSerialize
to  Hackage .

Read, Show and Data.Binary do not check for repeated references to the same
data address. As a result, the data is serialized multiple times when
serialized. This is a waste of space in the filesystem  and  also a waste of
serialization time. but the worst consequence is that, when the serialized
data is read, it allocates multiple copies in memory for the same object
referenced multiple times. Because multiple referenced data is very typical
in a pure language such is Haskell, this means that the resulting data loose
the beatiful economy of space and processing time that referential
transparency permits.

This package allows the serialization and deserialization of large data
structures without duplication of data, with
the result of optimized performance and memory usage. It is also useful for
debugging purposes.

There are automatic derived instances for instances of Read/Show, lists and
strings. the deserializer contains a almos complete set of Parsec.Token
parsers for deserialization.

 Every instance of Show/Read is also a instance of Data.RefSerialize

 The serialized string has the form expr( var1, ...varn) where
var1=value1,..valn=valueN  so that the
string can ve EVALuated.

 See demo.hs and tutorial. I presumably will add a entry in
haskell-web.blogspot.com

 To develop: -derived instances for Data.Binary
 -serialization to/from ByteStings

I wrote this module because I needed to serialize lists of verisions of the
same data with slight modifications between each version.


This is a short tutorial (in tutorial.txt)



runW applies showp, the serialization parser of the instance Int for the
RefSerialize class

Data.RefSerializelet x= 5 :: Int
Data.RefSerializerunW $ showp x
5

every instance of Read and Show is an instance of RefSerialize.

rshowp is derived from showp, it labels the serialized data with a variable
name

Data.RefSerializerunW $ rshowp x
 v8 where {v8= 5; }

Data.RefSerializerunW $ rshowp [2::Int,3::Int]
 v6 where {v6= [ v9,  v10]; v9= 2; v10= 3; }

while showp does a normal show serialization

Data.RefSerializerunW $ showp [x,x]
[5, 5]

rshowp variables are serialized memory references: no piece of data that
point to the same addrees is serialized but one time

Data.RefSerializerunW $ rshowp [x,x]
 v9 where {v6= 5; v9= [ v6, v6]; }

This happens recursively

Data.RefSerializelet xs= [x,x] in str = runW $ rshowp [xs,xs]
Data.RefSerializestr
 v8 where {v8= [ v10, v10]; v9= 5; v10= [ v9, v9]; }

the rshowp serialized data is read with rreadp. The showp serialized data is
read by readp

Data.RefSerializelet xss= runR rreadp str :: [[Int]]
Data.RefSerializeprint xss
[[5,5],[5,5]]

this is the deserialized data

the deserialized data keep the references!! pointers are restored! That is
the whole point!

Data.RefSerializevarName xss !! 0 == varName xss !! 1
True


rShow= runW rshowp
rRead= runR rreadp

Data.RefSerializerShow x
 v11 where {v11= 5; }


In the definition of a referencing parser non referencing parsers can be
used and viceversa. Use a referencing parser
when the piece of data is being referenced many times inside the serialized
data.

by default the referencing parser is constructed by:

rshowp= insertVar showp
   rreadp= readVar readp
but this can be redefined. See for example the instance of [] in
RefSerialize.hs

This is an example of a showp parser for a simple data structure.

data S= S Int Int deriving ( Show, Eq)

instance  Serialize S  where
showp (S x y)= do
xs - rshowp x  -- rshowp parsers can be inside showp
parser
ys - rshowp y
return $ S ++xs++ ++ys



readp =  do
symbol S -- I included a (almost) complete Parsec
for deserialization
x - rreadp
y - rreadp
return $ S x y

there is a mix between referencing and no referencing parser here:

Data.RefSerializeputStrLn $ runW $ showp $ S x x
S  v23 v23 where {v23= 5; }


(I corrected some errors in this file here)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Can't figure out source of race condition when using System.Process

2008-11-02 Thread Rafal Kolanski

Greetings Gentlemen (and Ladies),

As part of my small and simple framework for making presentations in 
Haskell I have a module which, given some text, makes a .tex file and 
then converts it to .svg for loading into a cairo canvas.
It features simple caching (performs md5 on the contents of the .tex 
file and uses that as the file name... if an .svg by that name exists, 
it'll get loaded rather than regenerated).


Unfortunately, it also segfaults once in a while, probably indicating I 
have some kind of race condition ... but I can't figure out why. This is 
the only point in my code that I think I'm using any concurrency, 
although I'm compiling with ghc --make -threaded. Compiling without 
-threaded results in a deadlock.


Ubuntu 8.10, 64-bit, GHC 6.8.2.

Any advice? I'm attaching the module in question (79 lines).

Sincerely,

Rafal Kolanski.
module LatexSVG (updateSVG, updateSVG') where

import System.Process
import Control.Concurrent (forkIO)
import Control.Monad (when)
import System.IO
import System.Directory (doesFileExist)
import System.Exit

workingDir = tex/

prefix = unlines $
   [\\documentclass{minimal} ,
\\usepackage{graphicx,latexsym,amsmath,url,color},
\\usepackage{amssymb,amsmath,wasysym, pst-node, color},
\\usepackage{url},
\\usepackage{isabelle,isabellesym},
%\\usepackage{mathpartir},
\\definecolor{dblue}{rgb}{0,0,0.4},
\\definecolor{blue}{rgb}{0,0,0.6},
\\definecolor{green}{rgb}{0,0.6,0},
\\definecolor{gray}{rgb}{0.7,0.7,0.7},
\\definecolor{dblue}{rgb}{0,0,0.6},
\\definecolor{darkgray}{rgb}{0.4,0.4,0.4},
\\definecolor{red}{rgb}{0.6,0,0},
\\begin{document}]

suffix = \n\\end{document}

-- Pass text to md5sum and drop the final   - when returning
hashMD5 text = do
(inp,out,err,pid) - runInteractiveProcess md5sum [] Nothing Nothing
forkIO $ do 
hPutStrLn inp text
hClose inp
exit - waitForProcess pid
case exit of ExitFailure _ - error md5sum fail 
 _ - return ()
md5hash - hGetContents out
return $ takeWhile (\x - x /= ' ') md5hash

blindExecWithFail cmd args dir = do
(inp,out,err,pid) - runInteractiveProcess cmd args (Just dir) Nothing
exit - waitForProcess pid
case exit of ExitFailure _ - error $ cmd ++   ++ (show args) ++ fail 
 _ - return ()

generateSVG text filebase = do
-- Create a .tex file
writeFile (workingDir ++ filebase ++ .tex) text
-- Run pdflatex over it
blindExecWithFail pdflatex [filebase] workingDir
-- Run pstoedit on resulting .pdf
blindExecWithFail pstoedit 
  [-page 1,-dt,-psarg,-r9600x9600, 
   filebase ++ .pdf, filebase ++ .sk] 
  workingDir
-- Run skconvert on resulting .sk
blindExecWithFail skconvert 
  [filebase ++ .sk, filebase ++ .svg]
  workingDir

updateSVG' :: [Char] - [Char] - [Char] - IO [Char]
updateSVG' prefix suffix text = do
-- Hash the tex
let tex = prefix ++ text ++ suffix
md5hash - hashMD5 tex
-- Filenames are the hash prefixed with hash and ending with extension
let filebase = hash ++ md5hash
-- See if an svg file by that name exists
svge - doesFileExist $ workingDir ++ filebase ++ .svg
when (not svge) $! do
putStrLn $ filebase ++ .svg does not exist, creating
generateSVG tex filebase
return $ workingDir ++ filebase ++ .svg

updateSVG :: [Char] - IO [Char]
updateSVG = updateSVG' prefix suffix

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: RefSerialize-0.2.1

2008-11-02 Thread Bulat Ziganshin
Hello Alberto,

Sunday, November 2, 2008, 5:02:10 PM, you wrote:
 Read, Show and Data.Binary do not check for repeated references to
 the same data address.

afair, SerTH does it, using GHC's internal address compare function

what way to check for copies you use?


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] Re: Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Mauricio

Hi,

I've reading Control.Monad.Reader source code and
arrived here:

class (Monad m) = MonadReader r m | m - r where

I can't understand that syntax. Since this is not a
'data' line, what is the '|' supposed mean?


It's called a functional dependency. This is not part of the 
Haskell-98 language standard; check the GHC manual.


The documentation says There should be more documentation, but there 
isn't (yet). Yell if you need it. :)


But I think I was able to understand everything from
the examples.

Thanks.

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


Re: [Haskell-cafe] Re: Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Bulat Ziganshin
Hello Mauricio,

Sunday, November 2, 2008, 6:13:15 PM, you wrote:

 It's called a functional dependency. This is not part of the
 Haskell-98 language standard; check the GHC manual.

 The documentation says There should be more documentation, but there 
 isn't (yet). Yell if you need it. :)

you probably don't found it. since 6.6 (or 6.8?) ghc includes great
tutorial on fundeps derived from hugs docs


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] ANNOUNCE: zlib and bzlib 0.5 releases

2008-11-02 Thread Duncan Coutts
I'm pleased to announce updates to the zlib and bzlib packages.

The releases are on Hackage:

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

What's new
==

What's new in these releases is that the extended API is slightly nicer.
The simple API that most packages use is unchanged.

In particular, these functions have different types:
compressWith   :: CompressParams   - ByteString - ByteString
decompressWith :: DecompressParams - ByteString - ByteString

The CompressParams and DecompressParams types are records of
compression/decompression parameters. The functions are used like so:

compressWith   defaultCompressParams { ... }
decompressWith defaultDecompressParams { ... }

There is also a new parameter to control the size of the first output
buffer. This lets applications save memory when they happen to have a
good estimate of the output size (some apps like darcs know this
exactly). By getting a good estimate and (de)compressing into a
single-chunk lazy bytestring this lets apps convert to a strict
bytestring with no extra copying cost.

Future directions
=

The simple API is very unlikely to change.

The current error handling for decompression is not ideal. It just
throws exceptions for failures like bad format or unexpected end of
stream. This is a tricky area because error streaming behaviour does not
mix easily with error handling.

On option which I use in the iconv library is to have a data type
describe the real error conditions, something like:

data DataStream = Chunk Strict.ByteString Checksum DataStream
| Error Error -- for some suitable error type
| End Checksum

With suitable fold functions and functions to convert to a lazy
ByteString. Then people who care about error handling and streaming
behaviour can use that type directly. For example it should be trivial
to convert to an iterator style.

People have also asked for a continuation style api to give more control
over dynamic behaviour like flushing the compression state (eg in a http
server). Unfortunately this does not look easy. The zlib state is
mutable and while this can be hidden in a lazy list, it cannot be hidden
if we provide access to intermediate continuations. That is because
those continuations can be re-run whereas a lazy list evaluates each
element at most once (and with suitable internal locking this is even
true for SMP).

Background
==

The zlib and bzlib packages provide functions for compression and
decompression in the gzip, zlib and bzip2 formats. Both provide pure
functions on streams of data represented by lazy ByteStrings:

compress, decompress :: ByteString - ByteString

This makes it easy to use either in memory or with disk or network IO.
For example a simple gzip compression program is just:

 import qualified Data.ByteString.Lazy as ByteString
 import qualified Codec.Compression.GZip as GZip

 main = ByteString.interact GZip.compress

Or you could lazily read in and decompress .gz file using:

 content - GZip.decompress $ ByteString.readFile file

General
===

Both packages are bindings to the corresponding C libs, so they depend
on those external C libraries (except on Windows where we build a
bundled copy of the C lib source code). The compression speed is as you
would expect since it's the C lib that is doing all the work.

The zlib package is used in cabal-install to work with .tar.gz files. So
it has actually been tested on Windows. It works with all versions of
ghc since 6.4 (though it requires Cabal-1.2).

The darcs repos for the development versions live on code.haskell.org.

I'm very happy to get feedback on the API, the documentation or of
course any bug reports.

Duncan

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


Re: [Haskell-cafe] ANNOUNCE: zlib and bzlib 0.5 releases

2008-11-02 Thread Bulat Ziganshin
Hello Duncan,

Sunday, November 2, 2008, 6:46:00 PM, you wrote:

 People have also asked for a continuation style api to give more control
 over dynamic behaviour like flushing the compression state (eg in a http
 server). Unfortunately this does not look easy.

can you gove more details on these? may be i can help


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] ANNOUNCE: zlib and bzlib 0.5 releases

2008-11-02 Thread Duncan Coutts
On Sun, 2008-11-02 at 19:07 +0300, Bulat Ziganshin wrote:
 Hello Duncan,
 
 Sunday, November 2, 2008, 6:46:00 PM, you wrote:
 
  People have also asked for a continuation style api to give more control
  over dynamic behaviour like flushing the compression state (eg in a http
  server). Unfortunately this does not look easy.
 
 can you gove more details on these? may be i can help

For details talk to Johan Tibell [EMAIL PROTECTED]

Suppose you're trying to work with a strict block IO strategy, like one
of these iterator style designs. What kind of api would one want to work
with that?

The constraint is that for a pure api, the zlib compression state must
be used in a single threaded, non-persistent style.

Additionally it would be nice to expose the zlib flush feature. This is
tricky in a straightforward design because it involves a branching
structure of possible operations, and we cannot split the zlib
compression state (at least not cheaply).

If we could do it persistently we could have something like:

data StreamState = OutputAvailable
 ByteString -- the output buffer
 StreamState-- next state
 | InputRequired
  (ByteString - StreamState) -- supply input
  -- or
  (Flush  - StreamState) -- flush
 | StreamEnd CheckSum
data Flush = FlushEnd
   | FlushSync
   | FlushFull

initialState :: StreamState

But obviously we cannot do this because we have to guarantee the single
threaded use of the stream state.

Duncan

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


[Haskell-cafe] Re: Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Mauricio

It's called a functional dependency. This is not part of the
Haskell-98 language standard; check the GHC manual.


The documentation says There should be more documentation, but there 
isn't (yet). Yell if you need it. :)


you probably don't found it. since 6.6 (or 6.8?) ghc includes great
tutorial on fundeps derived from hugs docs




It's here, on 'latest' directory:

http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#functional-dependencies

But yes, you're right, there's a lot of good examples and
explanations. But that comment is still there, just in
the end of the first paragraph.

Best,
Maurício

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


Re: [Haskell-cafe] Can't figure out source of race condition when using System.Process

2008-11-02 Thread Bryan O'Sullivan
2008/11/2 Rafal Kolanski [EMAIL PROTECTED]


 Unfortunately, it also segfaults once in a while, probably indicating I
 have some kind of race condition ... but I can't figure out why.


What is the it that segfaults? The Haskell program shouldn't, at least.

That said, your code for reading from child processes is wrong. You should
read all of a child's output strictly (i.e. hGetContents alone will not do
the trick) before you wait for its exit status. Your current scheme reverses
this order, and there is hence no guarantee that it will read anything from
the defunct child process. There's some possibility that this might be the
cause of your segfault, which to me would suggest the presence of a bug in
the runtime system.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Array bug?

2008-11-02 Thread Bertram Felgenhauer
Andrew Coppin wrote:
 Bertram Felgenhauer wrote:
 Yes, it's a known bug - a conscious choice really. See

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

 It's somewhat ironic that this behaviour was introduced by a patch
 that made arrays safer to use in other respects.

 ...so it's *not* going to be fixed then?

It's not going to be fixed by itself - the first comment for the
bug report basically asks interested parties to submit a proposal
for changing this.

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


Re: [Haskell-cafe] Re: Syntax question: class (Monad m) = MonadReader r m | m - r where

2008-11-02 Thread Austin Seipp
This message is literate haskell.

 {-# LANGUAGE FunctionalDependencies, MultiParamTypeClasses #-}
 {-# LANGUAGE TypeFamilies, EmptyDataDecls, FlexibleContexts #-}

Just to add on for people watching, a fundep pretty much just says that if:

 class Foo a b | a - b where
   bar :: a - b
   baz :: b - a

Then if you have an instance:

 data A -- we hold types abstract for simplicity
 data B
 data C
 
 u = undefined -- convenience
 
 instance Foo A B where 
   bar x = u
   baz y = u

Then there can be no other instance for the class Foo of the form 'A
x' where x /= B, e.g. it would be invalid to then have:

 -- uncommenting this will error:
 -- instance Foo A C where
 --   bar x = u
 --   baz y = u

Why? We have established in the class declaration that 'a' determines 'b'
and in an actual instance of that class (concretely) stated that in
this case, the type A determines the type B and that relation holds
true for any usage of the class (in something like a constraint.)

The only way the typechecker can resolve that /relation/ is if
(roughly speaking I think) the set of types that can be of type 'b'
given an already known type 'a' are constrained in some way.

If you do not have the fundep, then the class will work and so will
instances, but you will get ambiguous type errs when trying to use
functions of the type class.

 class Foo2 a b where
   foobar :: a - b
   foobaz :: b - a

In the usage of 'foobar,' with no functional dependency, the compiler
cannot determine the type 'b' because in the instances of of 'Foo' we
do not 'bind' types together in any way, so for any instance of 'Foo A
x' an x could work here:

 instance Foo2 Bool Int where
foobar x = u
foobaz y = u
 instance Foo2 Bool Char where
foobar x = u
foobaz y = u
 

This instance will compile, but attempting to use it does not:

$ ghci ...
GHCi, version 6.8.3: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( fundeps-assoc.lhs, interpreted )
Ok, modules loaded: Main.
*Main :t foobar
foobar :: (Foo2 a b) = a - b
*Main let z = foobar True

interactive:1:8:
No instance for (Foo2 Bool b)
  arising from a use of `foobar' at interactive:1:8-18
Possible fix: add an instance declaration for (Foo2 Bool b)
In the expression: foobar True
In the definition of `z': z = foobar True
*Main 


The compiler is not able to determine what to declare the result type
of 'foobar True' as, since there is both an instance of 'Foo2 Bool'
for multiple types!

However, in the original Foo class we do have a fundep, and so we know
that if we give 'bar' a value of type 'A' then we get a 'B' in return
- hence, the fundep is a relation and constrains the possible values
of the type variable 'b' in the declaration, so the compiler can
figure this out.

*Main let z = bar (u::A)
*Main :t z
z :: B
*Main 

Functional dependencies are a little tricky, but they can basically
set up relations between types however you want to (for example, using
a fundep of 'a - b, b - a' specifies a 1-to-1 correlation between
the types which instantiate 'a' and 'b'.)

However, there is an alternative which I think is far easier to grok
and can express the same 'set of equations' - associated types. I
think they are nicer mainly because they make the connections between
types in a /functional/ way, not a relational one (despite the name of
functional dependencies.)

For instance, the Foo class above could be rewritten as:

 class (Show a, Show (Boom a), Eq (Boom a)) = Foo3 a where
   type Boom a :: *
   barfoo :: a - Boom a
   bazfoo :: Boom a - a

This states that along with method declarations for an instance we
must also specify a type declaration - 'Boom' is an associated type
synonym that takes one type a, and the overall kind of 'Boom a' is *
(that is, it is a 'fully satured' type.) The functional part is seen
in the instance.

 instance Foo3 Bool where
   type Boom Bool = Int
   barfoo x = 10
   bazfoo y = u

So we can see 'Boom' as a function at the type level, indexed by
types.

*Main let z = barfoo True
*Main :t z
z :: Boom Bool
*Main print (z::Int)
10
*Main 

In this case evaluation is undefined but we can see that the equation
overall results in a type of 'Int' as the typechecker can unify the
types 'Boom Bool' and Int, even though we have to explicitly type it.

For an even better example, I think the type-vector trick is pretty
cute too (uses GADTs): 

http://thoughtpolice.stringsandints.com/code/haskell/misc/type-vectors.hs

This message is getting somewhat long but, I hope that's an adequate
explanation for those who might be hazy or interested. For more on
associated types you should probably look here:

http://haskell.org/haskellwiki/GHC/Indexed_types#An_associated_type_synonym_example

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


Re: [Haskell-cafe] Array bug?

2008-11-02 Thread Andrew Coppin

Bertram Felgenhauer wrote:

Andrew Coppin wrote:
  

Bertram Felgenhauer wrote:


Yes, it's a known bug - a conscious choice really. See

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

It's somewhat ironic that this behaviour was introduced by a patch
that made arrays safer to use in other respects.
  

...so it's *not* going to be fixed then?



It's not going to be fixed by itself - the first comment for the
bug report basically asks interested parties to submit a proposal
for changing this.
  


Well I certainly don't have the skill to fix it. (Presumably all that 
array stuff is hard-wired into the compiler.)


In my opinion, what we should have is

1. An interface that is guaranteed-safe, no matter how inefficient that is.

2. An interface that is guaranteed-efficient, no matter how unsafe that is.

3. It should be extremely easy to switch from one to the other.

You write your code against the safe interface, test it until you're 
happy with it, and then switch to the fast interface.


Currently, the safe interface actually allows out-of-bounds indicies 
(in a way which reveals the underlying implementation), and the fast 
interface isn't publicly supported. Both of these things should be changed.


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


Re: [Haskell-cafe] Memory efficiency questions for real-time graphics

2008-11-02 Thread T Willingham
On Sat, Nov 1, 2008 at 2:11 PM, Sebastian Sylvan
[EMAIL PROTECTED] wrote:
 On Sat, Nov 1, 2008 at 6:57 PM, T Willingham [EMAIL PROTECTED]

 The per-vertex computation is a quite complex time-dependent function
 applied to the given domain on each update.  Yet even if it were
 simple, I would still first implement the formulas in Haskell and
 leave the optimization for later, if at all.

 I'd be very surprised to see a vertex transform that would be faster to
 implement on the CPU than the GPU.

It appears you misunderstood complex time-dependent function.  This
is quite a bit of Haskell code involving a significant amount of
octonion algebra.  It could, in principle, be put on the GPU, however
that should be the very last step after everything else works.

 There are various ways of writing out your vertex data too, so if it doesn't
 change too often you can still do the transformation on the GPU,

As I previously stated, it changes every frame.

Take a highly complicated function and apply it to N vertices.  Now
increase N until the framerate is affected.  That is where I am.  It
is obvious that any N-sized allocations will cause the framerate to
stutter.  This is not just theoretical: I *see* it as I increase N
while it's running.  This is the point of my initial email, the
subject of which is memory efficiency.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Memory efficiency questions for real-time graphics

2008-11-02 Thread Don Stewart
t.r.willingham:
 On Sat, Nov 1, 2008 at 2:11 PM, Sebastian Sylvan
 [EMAIL PROTECTED] wrote:
  On Sat, Nov 1, 2008 at 6:57 PM, T Willingham [EMAIL PROTECTED]
 
  The per-vertex computation is a quite complex time-dependent function
  applied to the given domain on each update.  Yet even if it were
  simple, I would still first implement the formulas in Haskell and
  leave the optimization for later, if at all.
 
  I'd be very surprised to see a vertex transform that would be faster to
  implement on the CPU than the GPU.
 
 It appears you misunderstood complex time-dependent function.  This
 is quite a bit of Haskell code involving a significant amount of
 octonion algebra.  It could, in principle, be put on the GPU, however
 that should be the very last step after everything else works.
 
  There are various ways of writing out your vertex data too, so if it doesn't
  change too often you can still do the transformation on the GPU,
 
 As I previously stated, it changes every frame.
 
 Take a highly complicated function and apply it to N vertices.  Now
 increase N until the framerate is affected.  That is where I am.  It
 is obvious that any N-sized allocations will cause the framerate to
 stutter.  This is not just theoretical: I *see* it as I increase N
 while it's running.  This is the point of my initial email, the
 subject of which is memory efficiency.

I'm glad things are going well. Do you have the code somewhere for
review?


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


Re: [Haskell-cafe] number of references to a variable

2008-11-02 Thread wren ng thornton

Andrew Coppin wrote:

Jan-Willem Maessen wrote:
 Usually the clever thing you want to know is this is the sole 
 reference to the pointed-to object.


Does GHC have weak references? (I seem to recall it does...)



http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html


As for the uniqueness of a reference to an object, there are 
alternatives to reference-counting techniques. For example, the language 
Clean[1] builds it into the type system (to replace monads) and they've 
gotten very good performance results from doing so. There are other 
linear logic approaches as well, though porting any of these to Haskell 
would take a fair deal of work to make efficient. Certainly a worthy 
research goal, but probably not what you had in mind :)


[1] http://clean.cs.ru.nl/

--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [darcs-users] Poll: Do you need to be able to build darcs from source on GHC 6.6?

2008-11-02 Thread Juliusz Chroboczek
 I see.  If you're using the darcs 1 binary I would encourage you to
 upgrade.  If  you meant darcs 1 repository format then I would
 encourage you to consider darcs 1 hashed repository format.  You don't
 even have to upgrade the public facing repo.  Just 'darcs get --hashed
 ...'.

I mean that I'm currently using Debian's 1.0.3 on my stable servers, and
the old repository format all over the place.  I'm using 2.0.2 on my
desktop machines.

I will definitely switch to the Darcs 2 implementation at some point, but
Darcs 1 hasn't broken down yet, and I've got other stuff to do right now.

 The alternative is to build a static version of Darcs that I can install on
 my stable (soon to be oldstable) servers.

That might actually be the simplest solution, now I come to think about it.

 The alternative to both alternatives is to switch to git.

 Right.  But I hope you're not saying that because you find this thread
 upsetting.

No.  That was just a way of pointing out that other revision control
systems do not have such complex build dependencies.

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


Re: [Haskell-cafe] Re: is there a way to pretty print a module?

2008-11-02 Thread Derek Elkins
On Sun, 2008-11-02 at 19:34 +, Simon Richard Clarkstone wrote:
 Anatoly Yakovenko wrote:
  is there a way to pretty print a module?
  like:
 
  module Main where
  import Language.Haskell.TH
  main = do
   print $ pprint Main
 
  haskell-src should be able to do that.
  
  I think haskell-src requires you to read the module at run time.  I
  want to embed the contents of the module in my program.  Basically a
  program that can print itself.
 
 This is rather like the idea of a quine; a program the prints itself out 
 without referring directly to its own source code.  The usual Haskell 
 quine is:
 
 putStrLn$(\s-s++show s)putStrLn$(\\s-s++show s)
 
 If merely returning the source code is enough then you can do:
 
 (\s-s++show s)(\\s-s++show s)
 
 It could be more elegant if \ weren't both lambda and string escape.

So get rid of the lambda, ap(++)showap(++)show

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


Re: [Haskell-cafe] Re: is there a way to pretty print a module?

2008-11-02 Thread Simon Richard Clarkstone

Anatoly Yakovenko wrote:

is there a way to pretty print a module?
like:

module Main where
import Language.Haskell.TH
main = do
 print $ pprint Main


haskell-src should be able to do that.


I think haskell-src requires you to read the module at run time.  I
want to embed the contents of the module in my program.  Basically a
program that can print itself.


This is rather like the idea of a quine; a program the prints itself out 
without referring directly to its own source code.  The usual Haskell 
quine is:


putStrLn$(\s-s++show s)putStrLn$(\\s-s++show s)

If merely returning the source code is enough then you can do:

(\s-s++show s)(\\s-s++show s)

It could be more elegant if \ weren't both lambda and string escape.

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


Re: [Haskell-cafe] number of references to a variable

2008-11-02 Thread wren ng thornton

Alberto G. Corona wrote:

* Certainly a worthy research goal, but probably not what you had in mind
:)

*Not at all, My interest on that was on to improve RefSerialize. Although
the Clean people has done a superb job on optimization. By the way, I'm not
sure if uniqueness is the cause of his performance. I tested Haskell code
generated using Maybe with and without monad instance and the monad does not
impose any overhead at all.


Oh, I wasn't saying that monads impose any overhead. Rather, the Clean 
folks aren't fans of monads and so they use uniqueness typing in order 
to provide the same kind of solution to IO while retaining functional 
purity. GHC's implementation of IO is actually very similar under the 
hood to what Clean does, though that's not necessarily true of other monads.


Even though they seem to intersect at IO, the ideas of monads and linear 
logics are orthogonal. The big optimization trick with linear logic is, 
since you know when some object is uniquely referenced, you know when 
it's safe to destructively update it in situ. For example, you can 
reverse a spine-unique list in linear time with zero space (modulo 
registers) by just inverting the spine pointers as you traverse it. 
Since it's uniquely referenced, noone else will notice so referential 
transparency is preserved. Doing it this way saves on allocation costs 
and on garbage collection.


There are certainly other ways to use the information that some object 
is held only by a single reference, but Clean's optimizations are the 
first that leap to my mind.


--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Can't figure out source of race condition when using System.Process

2008-11-02 Thread Marc Weber
On Mon, Nov 03, 2008 at 01:02:12AM +1100, Rafal Kolanski wrote:
  Rafal Kolanski.
 -- Pass text to md5sum and drop the final   - when returning
 hashMD5 text = do
 (inp,out,err,pid) - runInteractiveProcess md5sum [] Nothing Nothing
 forkIO $ do 
 hPutStrLn inp text
 hClose inp
 exit - waitForProcess pid
 case exit of ExitFailure _ - error md5sum fail 
  _ - return ()
 [...]

Why do you use forkIO here? It's not necessary. The process will run in
background on its own. ?

It would help me tracking the problem down having a full compilable
example..

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


[Haskell-cafe] Re: Poll: Do you need to be able to build darcs from source on GHC 6.6?

2008-11-02 Thread Achim Schneider
Juliusz Chroboczek [EMAIL PROTECTED] wrote:

 No.  That was just a way of pointing out that other revision control
 systems do not have such complex build dependencies.

*cough*
% export USE=doc gtk iconv perl subversion bash-completion cgi curl cvs
emacs mozsha1 ppcsha1 threads tk vim-syntax webdav xinetd
% emerge git --emptytree -p |wc -l
381

% export USE=-doc gtk iconv perl subversion bash-completion cgi curl
cvs emacs mozsha1 ppcsha1 threads tk vim-syntax webdav xinetd
% emerge git --emptytree -p |wc -l
329

% export USE=-doc -gtk -iconv -perl -subversion -bash-completion -cgi
-curl -cvs -emacs -mozsha1 -ppcsha1 -threads -tk -vim-syntax -webdav
-xinetd emerge git --emptytree -p |wc -l
% emerge git --emptytree -p |wc -l
57

% USE=doc emerge darcs --emptytree -p | wc -l
329

(that's mostly because stuff like latex pulls the whole of x11 and gtk
with my current settings... I can't be arsed to figure all of that
out right now)

% USE=-doc emerge darcs --emptytree -p | wc -l
79


Now you can say that A severely crippled version of git has less source
dependencies, but don't ever claim that the build dependencies are
less _complex_. 17 package-specific use flags are rather extreme.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


Re: [Haskell-cafe] Can't figure out source of race condition when using System.Process

2008-11-02 Thread David Roundy
On Sun, Nov 02, 2008 at 09:15:25PM +0100, Marc Weber wrote:
 On Mon, Nov 03, 2008 at 01:02:12AM +1100, Rafal Kolanski wrote:
   Rafal Kolanski.
  -- Pass text to md5sum and drop the final   - when returning
  hashMD5 text = do
  (inp,out,err,pid) - runInteractiveProcess md5sum [] Nothing Nothing
  forkIO $ do 
  hPutStrLn inp text
  hClose inp
  exit - waitForProcess pid
  case exit of ExitFailure _ - error md5sum fail 
   _ - return ()
  [...]
 
 Why do you use forkIO here? It's not necessary. The process will run in
 background on its own. ?

It looks to me like this code requires a forkIO, not in the writing to inp,
but rather in the reading of out and err.  Otherwise, those buffers may
fill up and your process will hang...
-- 
David Roundy
http://www.darcs.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Memory efficiency questions for real-time graphics

2008-11-02 Thread T Willingham
On Sun, Nov 2, 2008 at 2:13 PM, Don Stewart [EMAIL PROTECTED] wrote:
 t.r.willingham:
 Take a highly complicated function and apply it to N vertices.  Now
 increase N until the framerate is affected.  That is where I am.  It
 is obvious that any N-sized allocations will cause the framerate to
 stutter.  This is not just theoretical: I *see* it as I increase N
 while it's running.  This is the point of my initial email, the
 subject of which is memory efficiency.

 I'm glad things are going well. Do you have the code somewhere for
 review?

If you read my initial post, you'll see that I am looking to convert
an existing C++ application to Haskell.  Above I am describing the
current C++ implementation.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: zlib and bzlib 0.5 releases

2008-11-02 Thread Henning Thielemann


On Sun, 2 Nov 2008, Duncan Coutts wrote:


The current error handling for decompression is not ideal. It just
throws exceptions for failures like bad format or unexpected end of
stream. This is a tricky area because error streaming behaviour does not
mix easily with error handling.


Maybe
   
http://hackage.haskell.org/packages/archive/explicit-exception/0.0.1/doc/html/Control-Monad-Exception-Asynchronous.html
  can be of help?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread T Willingham
I was surprised when I read the multi-core section of Real World
Haskell which explains the use of par, seq, and force to achieve
parallelism.

While it's obvious a programmer could provide useful parallelism hints
to the compiler, given the nature of the language I would have thought
Haskell could do a significant amount of parallelism itself without
any hints or code changes at all.

I am thinking of our troglodytic friend 'make', which will run (for
example) 4 parallel jobs when given the option make -j4.  Even
'rake', the ruby version of make, now has a branch (called drake)
which does the parallel -j option.

Since much of Haskell code is free of side effects, it would seem that
it can be analyzed in similar manner to Makefile dependencies in order
to find sections which can be run in parallel.

What would it take to implement a -j equivalent for, say, GHC?  Or if
this is not possible, what is wrong with my reasoning?

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


Re: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread Bulat Ziganshin
Hello T,

Monday, November 3, 2008, 2:28:08 AM, you wrote:

 What would it take to implement a -j equivalent for, say, GHC?  Or if
 this is not possible, what is wrong with my reasoning?

problem is that make have rather large pices of work which it can run
parallel. if ghc will try to parallel every machine operation, it will
pend more time maintaining these jobs. 'par' is just the way to tell
GHC this part of job is large enough


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread T Willingham
On Sun, Nov 2, 2008 at 6:44 PM, Bulat Ziganshin
[EMAIL PROTECTED] wrote:
 What would it take to implement a -j equivalent for, say, GHC?  Or if
 this is not possible, what is wrong with my reasoning?

 problem is that make have rather large pices of work which it can run
 parallel. if ghc will try to parallel every machine operation, it will
 pend more time maintaining these jobs. 'par' is just the way to tell
 GHC this part of job is large enough

Right, but couldn't the Haskell complier+runtime discover rather
large pieces of work?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread Don Stewart
t.r.willingham:
 On Sun, Nov 2, 2008 at 6:44 PM, Bulat Ziganshin
 [EMAIL PROTECTED] wrote:
  What would it take to implement a -j equivalent for, say, GHC?  Or if
  this is not possible, what is wrong with my reasoning?
 
  problem is that make have rather large pices of work which it can run
  parallel. if ghc will try to parallel every machine operation, it will
  pend more time maintaining these jobs. 'par' is just the way to tell
  GHC this part of job is large enough
 
 Right, but couldn't the Haskell complier+runtime discover rather
 large pieces of work?

Requires runtime profiling to work out the costs.

See this paper which implements this this idea,

  PDF
http://research.microsoft.com/~tharris/papers/2007-fdip.pdf

  HTML

http://209.85.173.104/search?q=cache:7cC4fQjCEH4J:research.microsoft.com/~tharris/papers/2007-fdip.pdf


Note that for subsets of Haskell, where we have more information
statically about the costs involves, we can do the parallelism
automatically. Data Parallel Haskell is the prime example.

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


Re: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread Luke Palmer
On Sun, Nov 2, 2008 at 12:42 PM, T Willingham [EMAIL PROTECTED] wrote:
 On Sun, Nov 2, 2008 at 6:44 PM, Bulat Ziganshin
 [EMAIL PROTECTED] wrote:
 What would it take to implement a -j equivalent for, say, GHC?  Or if
 this is not possible, what is wrong with my reasoning?

 problem is that make have rather large pices of work which it can run
 parallel. if ghc will try to parallel every machine operation, it will
 pend more time maintaining these jobs. 'par' is just the way to tell
 GHC this part of job is large enough

 Right, but couldn't the Haskell complier+runtime discover rather
 large pieces of work?

Perhaps, but not easily.  Especially if it can be done statically,
there is plenty of research to be done in this area.

Haskell is rather different from make.  The graph of a lambda calculus
program is not nearly as transparent as the graph of a makefile --
*especially* considering lazy evaluation.  For example, you might
think:

  map (+1) [1..1000]

Is a rather large piece of work, but if it is then applied to take
4, that is no longer true.  We don't want to be futilely spinning our
processor computing this.

So my guess is that there are some cases, in the same way as
strictness analysis, where you can identify these, but there are many
cases which are much more subtle and hard to identify automatically.
But I am no expert in the area.

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


[Haskell-cafe] Making 'community' server our social network

2008-11-02 Thread Maurí­cio

Hi,

I've  beeing doing  something with  darcs that  is so  great that,
although I'm  sure a lot of  people are already doing  the same, I
think it would be nice to share with you. I did 'cd ~' and then:

darcs initialize
darcs add .emacs
darcs add .xmonad/xmonad.hs
darcs add .inputrc
...
etc.

So I'm  using darcs to keep  track of all my  configuration files,
and now I  don't need to care about reinstalling  the OS, changing
machines  from office  to home,  changing configurations  and then
realizing it was a mistake etc.

Then I  thought community.haskell.org could offer  a default darcs
repositories for all users named after their owners. For instance,
if you want to check my personal files you would do:

darcs get http://code.haskell.org/MauricioAntunes

That would allow us not only  to share our configuration, but also
share all  those small  files that  are not  professional enough
to  became  projects for  their  own,  but that  are  nevertheless
interesting since  we put our  good ideas there: scripts  to start
our  favorite software  or  do system  maintenance; small  Haskell
utilities  to do  some cool  math  or science  trick, stress  some
language feature  or download  our standard music  collection from
the web;  a list of favorite  sites and a related completion script
so we can list then in 'dmenu' completion; etc. etc. etc.

The next bonus  step would be to  get a list at  all users default
repository main  page of all  other users they have  granted write
access  to some  of  their  projects. Then  we  would  be able  to
navigate throw linked  lists of people with  related interests and
needs.

I think we need  no more to get what will  be MySpace, Facebook or
something else for text-driven people.  And then, of course, world
domination.  Although I  don't really  imagine any  business model
around that :)

Best,
Maurício

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


[Haskell-cafe] a minimal Windows program in Haskell?

2008-11-02 Thread Nun Aurbiz
How do I make a minimal Windows application in Haskell?  I know there are Win 
API bindings in the libraries, and of course the ffi lets you call into and out 
of C, but I have no sense of how to bring it all together.  I can't find any 
samples either.

Is the Haskell code the main application and you just ffi into the Win API?  
Or does it ffi into a win_main.c that I write?  Or is the win_main.c the main 
application and it calls into Haskell?

Here is what I am talking about by a minimal Windows application (written in 
psuedo C code).

#define WIN32_LEAN_AND_MEAN
#include windows.h

LRESULT CALLBACK windowsProcedure(..) {
switch(message) {
case WM_CLOSE:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(..);
}

int APIENTRY WinMain(..){
WNDCLASS window_class;
RegisterClass(window_class)
window = CreateWindow(..);
ShowWindow(..);

while(true) {
/* do whatever */

while(PeekMessage(..))
if(msg.message ==  WM_QUIT)
return msg.wParam;
else
DispatchMessage(msg);
}
return 0;
}



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


[Haskell-cafe] ANNOUNCE: Graphalyze-0.5 and SourceGraph-0.3

2008-11-02 Thread Ivan Lazar Miljenovic
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I've just submitted my thesis this morning (w00t!!!) and as such I'm announcing
the latest versions of Graphalyze [1,2] and SourceGraph [3,4], which fix a
couple of bugs in the previous versions (these bugs were fixed whilst waiting
for my supervisor to finish reading through my draft, and as such I had to
re-write bits of my thesis that talked about the limitations of the
software :s ).

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Graphalyze
[2] http://code.haskell.org/Graphalyze
[3] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SourceGraph
[4] http://code.haskell.org/SourceGraph

Briefly, SourceGraph is a utility that uses the Graphalyze library to analyse
Cabalized Haskell software.  Its input/output is rather restrictive at
the moment: it takes a single argument, which is the path to a .cabal file, and
then produces an HTML report in:
  project directory/SourceGraph/project name.html
This report contains visualisation of the code for each module, for the imports
(similar to what graphmod [5] does) as well as the entire code base.
Furthermore, the entire code base is also visualised with functions grouped by
the modules they're defined in, as well some simple analyses (such as comparing
the export list to what functions are actually roots, similar to the output for
top-level functions returned by GHC when using -fwarn-unused-binds).

Main changes in Graphalyze since version 0.4:
* When writing my thesis, I found some obvious silly mistakes (such as copying
  the rootsOf function definition to leavesOf, but not changing the function
  definition).
* Images in the document representation are now inline elements.
* When using Pandoc [6] for document generation, the size of generated graphs
  is now customisable on a per-format basis; furthermore, for web pages graph
  visualisations link to larger versions.  Also, graph visualisations can now
  be created in a sub-directory.

Main changes in SourceGraph since version 0.2:
* Now uses Cabal 1.6
* Improve visual layout of generated HTML report (still no CSS though).
* Smarter analysis: don't show trivial analysis results, and when analysing
  the entire code base don't return cliques, etc. that contain functions all in
  the same module (as they would have been reported in the per-module section).

Note, however, that the parsing limitations for version 0.2 still apply: cpp is
still as-yet unsupported (as I'm not sure what I'll do about choosing cpp
flags); Template Haskell, HaRP and HXML are still ignored and functions in
class declarations/records are still ignored (the former because it's ambiguous
which actual function you want, the latter because they're boring :p ).  Also,
SourceGraph is _still_ not a refactoring tool ;-)

If anyone's interested, I'll soon be uploading the final version of my thesis
to my blog.  Also, if anyone is interested in hacking on any of this, feel
free!  I'll probably leave it for a while (I'm going to be doing Java coding
over summer, blech :s ), but I intend to come back to it later on.

- -- 
Ivan Lazar Miljenovic
[EMAIL PROTECTED]
IvanMiljenovic.wordpress.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkkOcaAACgkQfEfFJ9JhvyjhIwCeM9VXsJeSVK2CdWURJDer6zoA
A5YAoIfayHtjpw0qt/gyPZhhhypOwzSh
=x+/X
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Graphalyze-0.5 and SourceGraph-0.3

2008-11-02 Thread Ivan Lazar Miljenovic
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sun, 2 Nov 2008 22:43:27 -0500
Gwern Branwen [EMAIL PROTECTED] wrote:
 Darn! I was really hoping to analyze my XMonadContrib modules which use
 CPP. :(
 
 Come now, is it really so intractable? Why not try a dumb, but simple
 and understandable approach - like dropping everything inside CPP
 sections, and analysing the remainder? If it's clearly stated in the
 docs, I don't think any user could really blame you. If they insist,
 you could always add a flag like --strict-cpp ('So you prefer no
 results to somewhat wrong results? FINE.')

The main reason I haven't is due to lack of time... as it was, these last few
fix-ups were only done last-minute whilst I was waiting for my supervisor to
read through my draft (and mainly fixed what I perceived as _real_ bugs, not
just adding functionality).  Though, to be honest I didn't think about
performing sanitizing in that fashion...

Of course, if you really want that functionality you can add it ;-)



- -- 
Ivan Lazar Miljenovic
[EMAIL PROTECTED]
IvanMiljenovic.wordpress.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkkOdBkACgkQfEfFJ9JhvyhjYgCggEcRquF+BmZSCkVpxt3dY1sT
pI4AnjV5em0zVrTxHQtdf2J6ibOZ121d
=qd3I
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Arch Haskell News: Nov 02 2008

2008-11-02 Thread Don Stewart
News about the Haskell packages for Arch Linux.

Highlights,
   
* 672 Haskell packages now supported in Arch Linux, up 33 from two weeks 
ago.

Noteworthy,

* haskell-tcache-0.5.3: “A Transactional data cache with configurable 
persistence”
* haskell-yampa-0.9.2.3: “Library for programming hybrid systems.”
* haskell-network-bytestring-0.1.1.3: “Fast and memory efficient low-level 
networking”
* haskell-checkers-0.1.1: “Check properties on standard classes and data 
structures.”
* haskell-coreerlang-0.0.1: “Facilities for manipulating Core Erlang source 
code: an abstract syntax, parser and pretty-printer.”


Full update list,
 
http://archhaskell.wordpress.com/2008/11/03/arch-haskell-news-nov-02-2008/

-- Don

How's your favourite distro doing? If its not up to scratch, talk to someone.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread Ketil Malde
Bulat Ziganshin [EMAIL PROTECTED] writes:

 Hello T,

 Monday, November 3, 2008, 2:28:08 AM, you wrote:

 What would it take to implement a -j equivalent for, say, GHC?  Or if
 this is not possible, what is wrong with my reasoning?

 problem is that make have rather large pices of work which it can run
 parallel. if ghc will try to parallel every machine operation, it will
 pend more time maintaining these jobs. 'par' is just the way to tell
 GHC this part of job is large enough

..and also that this piece of work will actually need to be evaluated.  With
lazyness, a program can have subexpressions that are bottom as long as they are
not evaluated, any kind of speculative execution must take care to handle this
properly. 

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Automatic parallelism in Haskell, similar to make -j4?

2008-11-02 Thread Bulat Ziganshin
Hello T,

Monday, November 3, 2008, 3:42:49 AM, you wrote:

 On Sun, Nov 2, 2008 at 6:44 PM, Bulat Ziganshin
 [EMAIL PROTECTED] wrote:
 What would it take to implement a -j equivalent for, say, GHC?  Or if
 this is not possible, what is wrong with my reasoning?

 problem is that make have rather large pices of work which it can run
 parallel. if ghc will try to parallel every machine operation, it will
 pend more time maintaining these jobs. 'par' is just the way to tell
 GHC this part of job is large enough

 Right, but couldn't the Haskell complier+runtime discover rather
 large pieces of work?

are you ever herd about halting problem? it's imposible in general
case and i doubt how far it may be done on practice. in general, it
looks close to really compute the function (and you still need to know
its actual input params!)

anyway it's not done and i don't heard about researches in this
direction


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Making 'community' server our social network

2008-11-02 Thread Bulat Ziganshin
Hello Maurí­cio,

Monday, November 3, 2008, 4:43:26 AM, you wrote:

 darcs add .emacs

 darcs get http://code.haskell.org/MauricioAntunes

thank, it's a great ideas! and don't forget that you can use
code.haskell.org as online backup of history of your config files


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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