Re: Syntax dubion

1998-06-26 Thread Erik Meijer

In an ideal world, the Haskell grammar would be simplified by merging
the rules for pattern syntax with those for expression syntax.


Yes, Alastair is right once again! Hurray for less syntax but more static
semantics.

Erik





Re: Syntax dubion

1998-06-26 Thread Ralf Hinze

 if I write
 
 (a  b) x = a x  b x
 
 hugs accepts it, but ghc rejects it.  I think that ghc is correct in
 that the report only allows 
 
  funlhs 
 - 
var apat {apat } 
 | 
pati+1 varop(a,i) pati+1 
 | 
lpati varop(l,i) pati+1 
 | 
pati+1 varop(r,i) rpati 
 
 ie no () and no extra arguments, but given that one may want to define
 higher order functions this way, we ought to make the language allow it.
 
 Can anyone argue against it?

No, I have been bitten by this restriction several times (I even sent
a similar script as a bug to glasgow-bugs). On page 90 of the Haskell
Report we even find

f . g = \ x - f (g x)

while Miranda TM allows

(f. g) x = f (g x)

Taking Miranda's syntax as a source of inspiration we could
modify funlhs to 

  funlhs- var apat {apat} 
|  pati+1 varop(a,i) pati+1 
|  lpati varop(l,i) pati+1 
|  pati+1 varop(r,i) rpati 
|  pati+1 varop(r,i) rpati 
|  ( funlhs ) {apat}

Any objections?

Cheers, Ralf





Syntax dubion

1998-06-26 Thread Jon . Fairbairn

if I write

(a  b) x = a x  b x

hugs accepts it, but ghc rejects it.  I think that ghc is correct in
that the report only allows 

 funlhs 
- 
   var apat {apat } 
| 
   pati+1 varop(a,i) pati+1 
| 
   lpati varop(l,i) pati+1 
| 
   pati+1 varop(r,i) rpati 

ie no () and no extra arguments, but given that one may want to define
higher order functions this way, we ought to make the language allow it.

Can anyone argue against it?

-- 
Jon Fairbairn [EMAIL PROTECTED]
18 Kimberley Road[EMAIL PROTECTED]







Re: what is leaking?

1998-06-26 Thread Ralf Hinze

 When I try to execute this:
 
  result = foldl (+) 0 [1..10]
  main = putStr $show (result `mod` 10)
 
 Hugs gives: ERROR: Garbage collection fails to reclaim sufficient space
 GHC gives: Stack space overflow: current size 262152 bytes.
 
 Why would this have an error?  The list should be constructed lazily as it
 is consumed by the sum.  I assume I have a space leak but I can't figure
 out why.

`foldl' constructs the expression ... 3+(2+(1+0)) but does not evaluate
it. A common space leak with lazy evalution, see Paulson, ML for the
working programmer, p.47. Try this one 

 strictFoldl   :: (Eval b) = (b - a - b) - b - [a] - b
 strictFoldl (*)   =  f
 where f e []  =  e
   f e (a:x)   =  strict f (e * a) x

 result=  strictFoldl (+) 0 [1..10]
 main  =  putStr $ show (result `mod` 10)

Cheers, Ralf





Re: what is leaking?

1998-06-26 Thread S. Alexander Jacobson

Wow! If Ralf is right, then foldl in a lazy language always generates a
space leak and should be avoided in favor of strictFoldl.  

However, I still am not clear why explicity strictness is required for
foldl to behave properly.  In fact it seems like the problem is
insufficient laziness.

If you use a different (but still lazy) definition of foldl:
 myFoldl f s [] = s
 myFoldl f s (x:xs) = f s (foldl f x xs)

Alastair and Ralf say you get this spaceleak:
total = myFoldl (+) 0 [1..10]
...
total = 0 + 1 + 2 + (myFoldl (+) 3 [4..10])
...

But, why isn't foldl evaluated lazily?
Addition is left associative so computation of total should consume
addition operations until it needs to make the next fold.  So you would
have:

 total = 3 + (myFoldl (+) 3 [4..10])

Folding again generates another addition to consume:

 total = 3 + 4 + (myFoldl (+) 4 [5..10])

Then Haskell should add 3+4 and then call myFoldl again.

My alternative definition of foldl also causes both hugs and ghc to fail
so either Haskell is insufficiently lazy or my analysis in incorrect. 
I assume the later, but I don't understand why. (The explanation is
Paulson didn't help and I don't have Bird)

As an aside, I think strictFoldl is not automatically paralellizable, but
myFoldl may be. Specifically, if the compiler can deduce that addition is
fully associative, it would know that:

 total = (myFoldl (+) 0 [1..5]) +  (myFoldl (+) 50001 [50002..10])

And compute the individual myFoldls on separate processors.
(I know very little about parallel computing so this is just an intuition)

-Alex-
___
S. Alexander Jacobson   i2x Media  
1-212-697-0184 voice1-212-697-1427 fax

On Fri, 26 Jun 1998, Ralf Hinze wrote:
  When I try to execute this:
  
   result = foldl (+) 0 [1..10]
   main = putStr $show (result `mod` 10)
  
  Hugs gives: ERROR: Garbage collection fails to reclaim sufficient space
  GHC gives: Stack space overflow: current size 262152 bytes.
  
  Why would this have an error?  The list should be constructed lazily as it
  is consumed by the sum.  I assume I have a space leak but I can't figure
  out why.
 
 `foldl' constructs the expression ... 3+(2+(1+0)) but does not evaluate
 it. A common space leak with lazy evalution, see Paulson, ML for the
 working programmer, p.47. Try this one 
 
  strictFoldl :: (Eval b) = (b - a - b) - b - [a] - b
  strictFoldl (*) =  f
  where f e []=  e
f e (a:x) =  strict f (e * a) x
 
  result  =  strictFoldl (+) 0 [1..10]
  main=  putStr $ show (result `mod` 10)
 
 Cheers, Ralf
 










Re: Syntax dubion

1998-06-26 Thread Alastair Reid

 if I write
 
 (a  b) x = a x  b x
 
 hugs accepts it, but ghc rejects it.  I think that ghc is correct in
 that the report only allows ...

Yes, GHC adheres to the report more closely than Hugs.

However, the fact that you typed it in suggests that it's a reasonable
thing for Standard Haskell to support.   It's a regular source of bug
reports on both mailing lists.

In an ideal world, the Haskell grammar would be simplified by merging
the rules for pattern syntax with those for expression syntax.

Of course, then the syntax would "allow" expressions like this:

  x@(l,r)

and patterns like this:

  (foo bar)
  [ x | x - xs ]

We'd have to shift the burden of detecting these problems to the static
semantics (which is how things are done in Gofer and Hugs).

Gains:
o a slightly more expressive language
o a simpler grammar 
  About 20 rules vanish instantly.
  Also, I think it's easier to say "patterns are just like expressions
  except they can't contain list comprehensions, function call or ..."
  and expressions are not allowed to contain "@".
o parsing becomes simpler
  eg wWhen parsing a qualifier in a let comprehension, you can't tell
   if the qualifier is a guard or a pattern binding until you find 
   - or , or ].  That's why Mark implemented things the way he did.

Losses:
o some syntax errors are detected marginally later
  I don't recall anyone ever complaining when Hugs does this.
o muddies the waters between syntax and static semantics
  - but I don't think the waters are that clear to start with.

-- 
Alastair Reid  Yale Haskell Project Hacker
[EMAIL PROTECTED]  http://WWW.CS.Yale.EDU/homes/reid-alastair/






Re: Haskell ODBC implementation

1998-06-26 Thread sproot

The reason I am using Transaction rather than Connection is because I am
assuming that the database provides a transaction isolation model in which
the database is required to remain in the same state (from the point
of view of the client) until the transaction is committed.  Therefore any
function which does queries can be assured of referential transparency for
the duration of the transaction.  In the mail I sent, I included a
transact function which takes (transaction - [SQLChange]) as an argument
and applies the changes in the order specified by the list.

Let's not confuse something green with something hot:)
Neither me nor anybody else in this list uses term Connection rather than Transaction.

Suppose we use ODBC to work with database.
The process starts from loading ODBC DLLs, initialization of them.
Next client must connect to data source. This causes loading of proper ODBC driver and 
takes pretty long time. 
After connection was established client program is able to run SQL statements on this 
data source. What's the difference between Statement and Transaction? ODBC provides 
two modes - Automatic and Manual. Automatic is default mode which runs any Statement 
being executed on database immediately. Manual mode keeps executed Statements until 
they are all fired by SQLTransact call. That's all the difference. It doesn't matter 
what DBMS one is working with as long as it is treated as ODBC source. No difference 
between dBase III and Oracle 8 ;))
Next  - obtaining data. One can say that SQL query doesn't change database state. 
There are some more difficult questions about this.
First ODBC scheme is connect - run query - get data - disconnect.
You have to get data as IO action unless you incorporate all these scheme within 
unsafePerformIO call. Otherwise you will be surprised getting data before running 
query.
Second, World is changing even when database is not. Consider fetching data. Imagine 
you are going to fetch table of 10...0 rows. Traditional ODBC scheme is allocate 
memory buffers, bind them with table columns and fetch data row by row. Haskell can't 
fetch data row by row to memory buffers.  I used lazy list in my Haskell-ODBC 
interface to achieve this. Thus I allocate memory (IO action), bind it with columns 
(IO action) and return suspended _IO_action_. The action being returned is to fetch 
row of table (IO action again). And at last memory must be freed (once more IO action).
You see that suspension is IO action. 

My instinct is that it should be possible to automatically-serialize
haskell datastructures into an SQL database if they derive Read and Show.
It should also be possible to translate list comprehensions into a 
combination of server side SQL Select and client side Haskell.  However,
that really is research.  


Depends on what do you mean by automatically. It seems not to be so hard since most 
ODBC drivers support representing almost all of the possible types as strings. Just 
create table and put there strings with my interface :) 


Best regards, 
    Dima Skvortsov






what is leaking?

1998-06-26 Thread S. Alexander Jacobson

When I try to execute this:

 result = foldl (+) 0 [1..10]
 main = putStr $show (result `mod` 10)

Hugs gives: ERROR: Garbage collection fails to reclaim sufficient space
GHC gives: Stack space overflow: current size 262152 bytes.

Why would this have an error?  The list should be constructed lazily as it
is consumed by the sum.  I assume I have a space leak but I can't figure
out why.

-Alex-
___
S. Alexander Jacobson   i2x Media  
1-212-697-0184 voice1-212-697-1427 fax