Heap profiling dumped NULs

2003-09-23 Thread Ketil Z. Malde

Hi,

I can't reproduce it, but on one occasion running profiling with -hd,
I got corrupt .hp output, with a large block of NULs in an otherwise
normal output (The output is large, but I can make it available if
anybody wants it).  Rerunning the exact same command line produced a
normal .hp.

Just in case you'd like to know.

(GHC 6.0 from RPM on RH 9)

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[ ghc-Bugs-806622 ] fileExist throws exception when file does not exist

2003-09-23 Thread SourceForge.net
Bugs item #806622, was opened at 2003-09-15 16:19
Message generated for change (Settings changed) made by simonmar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=806622group_id=8032

Category: hslibs/posix
Group: 6.0.1
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Simon Marlow (simonmar)
Summary: fileExist throws exception when file does not exist

Initial Comment:
In ghc 6.0.1 function fileExist incorrectly throws exception 
when file does not exist. 

--

Comment By: Simon Marlow (simonmar)
Date: 2003-09-23 14:41

Message:
Logged In: YES 
user_id=48280

Fixed, thanks.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=806622group_id=8032
___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[ ghc-Bugs-806633 ] doesDirectoryExist / == False

2003-09-23 Thread SourceForge.net
Bugs item #806633, was opened at 2003-09-15 16:35
Message generated for change (Comment added) made by simonmar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=806633group_id=8032

Category: None
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Simon Marlow (simonmar)
Summary: doesDirectoryExist / == False

Initial Comment:
doesDirectoryExist gives False when called with root dir, /. 
 
I think that the following patch corrects this (I have not tried yet): 
 
$ diff -u Directory.hs,orig Directory.hs 
--- Directory.hs,orig   2003-04-11 12:11:24.0 +0200 
+++ Directory.hs2003-09-15 18:22:56.0 +0200 
@@ -597,7 +597,7 @@ 
   
 fileNameEndClean :: String - String 
 fileNameEndClean name = 
-  if i = 0  (ec == '\' || ec == '/') then 
+  if i  0  (ec == '\' || ec == '/') then 
  fileNameEndClean (take i name) 
else 
  name 
 
 
[EMAIL PROTECTED] 
 

--

Comment By: Simon Marlow (simonmar)
Date: 2003-09-23 14:46

Message:
Logged In: YES 
user_id=48280

Fixed, thanks.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=806633group_id=8032
___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[ ghc-Bugs-631320 ] {-# OPTIONS -O0 #-} not allowed

2003-09-23 Thread SourceForge.net
Bugs item #631320, was opened at 2002-10-30 23:57
Message generated for change (Comment added) made by simonmar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=631320group_id=8032

Category: Compiler
Group: 5.04.1
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: {-# OPTIONS -O0 #-} not allowed

Initial Comment:
When I tried to turn off the pessimizer for certain
files it complained that the -O0 option was not allowed
in the file.  Very annoying.

[EMAIL PROTECTED]

--

Comment By: Simon Marlow (simonmar)
Date: 2003-09-23 14:53

Message:
Logged In: YES 
user_id=48280

Fixed, eventually.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=108032aid=631320group_id=8032
___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: Haddock interface file for standard libraries

2003-09-23 Thread Peter Simons
Simon Marlow writes:

  /usr/share/ghc-6.0.1/html/*/*.haddock.

Hmm, why is it that every question I asks resolves in a way that makes
me look blind or dumb? :-)

Thanks for the quick help!

Peter
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


RE: Haddock interface file for standard libraries

2003-09-23 Thread Simon Marlow
 
 I have another short question concerning the build process: Is there
 any easy way to generate a Haddock interface file for the standard
 libraries? I'd like my own documentation to contain links to standard
 data types and functions, but processing the library sources directly
 turned out to be difficult because of pre-processor use etc.

A GHC distribution comes with the appropriate .haddock files - take a
look in eg. /usr/share/ghc-6.0.1/html/*/*.haddock.

Cheers,
Simon
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


WINNING NOTIFICATION !

2003-09-23 Thread marcwilliams
   
  ELGORDO DE LAPRIMITIVA  
   
C/GUZMAN EL BUENO,137
   
   MADRID - ESPAÑA 
   
TELE/  FAX:+34 916 470 023
   
  E-mail: [EMAIL PROTECTED]

FROM: THE DESK OF THE PROMOTIONS MANAGER, 
INTERNATIONAL PROMOTIONS/PRIZE AWARD DEPARTMENT, 
REF: LP/26510460037/03 
BATCH: 24/00319/IPD

RE: AWARD NOTIFICATION FINAL NOTICE 

We are pleased to inform you of the release today, 23rd  September 2003,of the ELGORDO 
SWEEPSTAKE LOTTERY/INTER-NATIONAL PROGRAMS held on the 14th September,2003. 
Your  name attached to ticket number 025 11464992-750 with serial number 2113-05 drew 
the lucky number 3-18-19-30-32-39, which consequently won the lottery in the 3rd 
category. 

You are therefore been approve for the lump sum pay out of €uros 1,547,000.87 (One 
Million Five Hundred and Fourty Seven Thousand Eighty Seven Cents .) in cash credit to 
the file REF: LP/26510460037/03. This is from a total prize of €uros 26,299,000.00 
share among the seventeen (17) International winners in this category. 

CONGRATULATION! 

Your fund is now deposited with a Security Company EURO CREDIT COMMISION. Due to the 
mixed up of some numbers and names, we ask that you keep this award a top secret from 
the public notice until your claim as been processed and your prize money remitted to 
your account as this is a part of our Security protocol to avoid double claiming award 
or unwarranted taking advantage of this program by participants. 

All participants were selected through a computer ballot system drawn from 25,000 
names from Australia, USA,  Europe, Asia ,New Zealand, Middle-East and South-North 
America .As part of our international promotions program, which we conducted once in a 
year. We hope with a part of your prize, you will take part in our end of the year 
high stake €uros 300 Million International Lottery. 

To being your claim, please contact the issuing authority, your prize claim agent, Mr. 
Barry Hanson, (Foreign Service Manager) for processing and remittance of your prize 
money to a designated account of your choice. Tel: +34 -639 280 825 .Email:[EMAIL 
PROTECTED], Remember, all prize money must be claimed not later until than the 23rd  
September, 2003. After this date, all funds will be returned as unclaimed. 

Note: In order to avoid unnecessary delays and complications, please remember to quote 
your reference and batch numbers in every of your correspondence with your agent. 
Furthermore, should there be any address do inform your claims agent as soon as 
possible. 

Please remember to ask for your prize claim certificate. 
Congratulation again from all member of our staff and thank you for being part of our 
promotion program. 

Best regards, 

MARIA JOSE SANCHEZ.
 

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


COOPERATION

2003-09-23 Thread SADKO INTERNATIONAL COMPANY
 



Dear Ladies and Gentlemen
Those yahcts which listed below will offer you %10 commission,
In this list below the prices are very low than the worlds market.

O L G A P R I C E 440.000 
   



 PROPERTIESEQUIPMENTSACOMMODATION 
 Type Ketch Dingy, 21 kWa Generator4Double Cabins
 Wc+ Shower

 Loan 26.00 mt 80ft 
 Hydrolic Lift, Music System1Master cabin Wc+shower

 Beam 6,80 mt 20ft  Tv, Vhf, Radar, Gps, Sonar,Full air
 conditioned,Hot Water

 Fuel Tank 4,000 lt  Fishing  Diving EquipmentHolding Tang,
 Ice Maker

 Rigging Furling  Wind Surf, Canoe, Jet skiDeep
 Freeze, Max.14 Person

 Water Tank 7,000 lt  Life Rafts for 25 personsDate of building 2001

 Engines 440 Man Turbo Original Marin



===Motor Yacht, Sunseeker P R I C E 1.550.000 

   

At the moment Sunseeker Manhattan 74 is moored in Bodrum. (very close to Kos Island). 

We will be glad to guide you in Bodrum. TVA is paid. it s built in 1999 in POOL , ENGLAND LOA: 22 m (66ft) BEAM: 7 m (21ft), 2 generators 20 V and 12 V, 220 V 2 engines 1100 hp Man navigation time: 351 hours Kitchen includes dish washer, refrigerator, microwave, hotplate, ice maker. 

2 deepfreeze electric windows, 4 cabins + 1 cabin for crew. Each cabin has a tv and music system wc and shower. central aircondition. diving equipment. As you understand from navigation time boat is not used regularly.

Boat never faced with an accident. Boat was not used for charters



==T U Z L A P I A N OPRICE 135.000 ==
 
Type : Motor BoatMain Engine: 150 Hp CumminsEquipment Tv Stereo Musi System 
Port: Bodrum TURKEYGenerator: 12 kvA 220 VRefrigirator Dingy2.60
   Date of Construction: 1992 Water Tanks: 1200 ltZodiak Boat
   LOA: 13.20m-40 ftFuel Tanks : 1000 lt
  BEAM:4.30m-13 ftAcommodation: 2 Master Cabin 


 





==S A D K O 282PRICE 125.000 =



LOA : 22.50 M / 74 FT ENGINE: 240HP DELPHIN BUILT: 1994 HULL: PINE / MAHOGANYI NTERIOR: MAHOGANY CABINS : 8 DOUBLE CABINS ALL CABINS WITH EN-SUITE WC+SHOWER GUEST CAPACITY: 16 ELECTRICITY : 12V WCs  SHOWERS : FLUSH TYPE WCs  ENCLOSED SHOWERS CREW : 1CAPTAIN, 1CHEF, 2 DECHANDS WATER CAPACITY: 6.000L FUEL CAPACITY: 2.000L WASTE WATER CAPACITY : 1.500L OTHER EQUIPMENT - TEAK DECK, GALVANIZED RIGGING, ALL CABINS WITH EN-SUITE WC  SHOWERS AND HOT WATER, ICE BOXES , 2 STEERING POSITIONS, HYDRAULIC WINDLASS, SUN MATRESSES, DECK CHA
 Your sincerely

Sadko Travel  Yachting 

 General Manager

 HacýAKDEMIR

 Manager

Sadettin AKDEMIR



Mobile:+ 90 536 6371646

 +90 537 2732137

Tel: +90 252 3135235 

Fax: +90 252 3135236



BODRUM OFFICE ISTANBUL OFFICE MOSCOW OFFICE

Cumhuriyet caddesi No:53Ordu Caddesi No:292 Minsk Otel Kat: 7

Bodrum-MUGLA/TURKEYLaleli-ISTANBUL/TURKEYMOSCOW/RUSSIA

 

http://www.sadkoyachting.com



[EMAIL PROTECTED]



[EMAIL PROTECTED]



[EMAIL PROTECTED]



We wish you a great success in your business.









___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: pretty newby

2003-09-23 Thread Malcolm Wallace
Luc Taesch [EMAIL PROTECTED] writes:

 are there any facility to pretty print an haskell program ?
 im aware of HPJ combinators library, but i was looking for a command line
 utility, rather.. am i missing an entry in HPJ ?

To some extent, you can use an ordinary Haskell compiler to
pretty-print your Haskell code.  For instance, among the various
debugging options in nhc98, the compiler has the option
+CTS -parse -CTS
to show the abstract syntax tree of a module immediately after parsing it.
(Other options show the syntax tree at other stages of the compilation,
such as after desugaring of field-syntax, type-checking, etc.)
I'm sure that ghc must have something similar.

In nhc98 there are also various options to control the 'look' of the
output of the pretty-printer, e.g.
-showqualified
-noshowqualified
-showwidth=80
-showident=4

Regards,
Malcolm
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: pretty newby

2003-09-23 Thread Per Larsson
On Tuesday 23 September 2003 16.05, Luc Taesch wrote:
 are there any facility to pretty print an haskell program ?
 im aware of HPJ combinators library, but i was looking for a command line
 utility, rather.. am i missing an entry in HPJ ?

 thanks
 Luc
 ___
 Haskell mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell

Hi,
In GHC (and HUGS?) you can use the 'haskell-src' package which contains
functions for parsing and pretty-printing haskell code. Using these, it only 
takes a couple of lines to make your own command line, pretty-printer for 
haskell code. If you want to, you can use my implementation which I attach to 
this mail. The problem with the parser, however, is that it doesn't handle 
comments at all.

Regards
Per-- FILE: HsIndent.hs
-- AUTH: Per Larsson
-- DATE: 03/10/2003
-- CODE: Haskell Code

module Main where

import System.Environment
import System.Exit
import System.IO
import Control.Monad
import Language.Haskell.Parser
import Language.Haskell.Pretty
import System.Console.GetOpt

header  = hsindent [OPTION ...] FILE
version = hsindent 1.0
usage   = usageInfo header options

data Config = Config {showHelp, showVersion :: Bool, pmode :: PPHsMode}
 
defaultConfig = Config False False defaultStyle

defaultStyle :: PPHsMode
defaultStyle = PPHsMode { 
classIndent = 8,
doIndent = 3,
caseIndent = 5,
letIndent = 4,
whereIndent = 6,
onsideIndent = 2,
spacing = True,
layout = PPOffsideRule,
linePragmas = False,
comments = True
  }

options :: [OptDescr (Config - Config)]
options = 
[ opt 'h' help print this help information and exit 
  (\c - c {showHelp = True}) 
, opt 'v' version print version information and exit
  (\c - c {showVersion = True})
, opt 'u' nospacing don't insert blank lines
  (\c - c {pmode = (pmode c) {spacing = False}})
, opt 'p' pragmas  insert source pragmas 
  (\c - c {pmode = (pmode c) {linePragmas = True}})
, opt 'e' comments  keep comments 
  (\c - c {pmode = (pmode c) {comments = True}}) 
, arg 's' class N indent class declarations N columns 
  (\s c - c {pmode = (pmode c) {classIndent = read s}})
, arg 'd' do N indent do expressions N columns
  (\s c - c {pmode = (pmode c) {doIndent = read s}}) 
, arg 'w' where N indent where expressions N columns 
  (\s c - c {pmode = (pmode c) {whereIndent = read s}})
, arg 'l' let N indent let expressions N columns
  (\s c - c {pmode = (pmode c) {letIndent = read s}})
, arg 'c' case N indent case expressions N columns 
  (\s c - c {pmode = (pmode c) {caseIndent = read s}})
, arg 'o' onside N indent at line continuations N columns 
  (\s c - c {pmode = (pmode c) {onsideIndent = read s}})
, arg 'y' layout  ARG set layout style to ARG, one of\n\
  \ 'OffsideRule', 'SemiColon', 'Inline' or 'NoLayout'
  (\s c - c {pmode = (pmode c) {layout = toLayout s}})  
] 
   where
   opt short long msg update = 
   Option [short] [long] (NoArg update) msg
   arg short long argdescr msg update = 
   Option [short] [long] (ReqArg update argdescr) msg
  
toLayout :: String - PPLayout
toLayout OffsideRule = PPOffsideRule
toLayout SemiColon   = PPSemiColon
toLayout InLine  = PPInLine
toLayout NoLayout= PPNoLayout
toLayout _ = error toLayout

--   

main = do 
args - getArgs
(conf,files) - case getOpt Permute options args of
(o,n,[])   - return (foldr ($) defaultConfig o, n)
(_,_,errs) - error (concat errs ++ usageInfo header options) 
when (showHelp conf) (exitSuccess usage)
when (showVersion conf) (exitSuccess version)
unless (length files == 1) (exitFail usage)
file - return (head files)
h - openFile file ReadMode
s - hGetContents h
result - return (parseModuleWithMode (ParseMode file) s)
case result of
ParseOk hsModule - 
exitSuccess (prettyPrintWithMode (pmode conf) hsModule)
ParseFailed pos msg - 
exitFail (Parse Error at:  ++ show pos ++ \n  ++ show msg)
where 
exitSuccess msg = (putStrLn msg  exitWith ExitSuccess)
exitFail msg = (putStrLn msg  exitFailure)
 


___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: pretty newby

2003-09-23 Thread Nick Name
Alle 16:05, martedì 23 settembre 2003, Luc Taesch ha scritto:
 are there any facility to pretty print an haskell program ?

If what you need is an external program and not a library, have a look 
at GNU a2ps.

Vincenzo

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: lexer puzzle

2003-09-23 Thread Marcin 'Qrczak' Kowalczyk
  Thus, the only possible lexical interpretation is the one you first
  suggested, namely a constructor A followed by a three-dot operator
  

 A... should be split into A.. and .

I found a compromise: let's make it a lexing error! :-)

-- 
   __( Marcin Kowalczyk
   \__/   [EMAIL PROTECTED]
^^ http://qrnik.knm.org.pl/~qrczak/

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: Thanks: (was Question about categories)

2003-09-23 Thread Florian Hars
Bill Halchin wrote:
  Here is the book plus many other llongo papers: 
http://www.di.ens.fr/users/llongo/download.html
s/llongo/longo/

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: garbage collection and Ptr/ForeignPtr/StablePtr

2003-09-23 Thread Alastair Reid
On Monday 22 September 2003 12:10 pm, Bayley, Alistair wrote:
 Should I expect that Ptr memory allocated with malloc is garbage collected
 when no longer used by the Haskell runtime? The FFI spec doesn't say so
 explicitly (that I could see); 

C programs use pointers in many ways: pointers to static objects, pointers to 
stack-allocated objects, etc. as well as pointers to malloc-allocated 
objects.  These are all represented with a 'Ptr' in Haskell but only one of 
them should be freed.

Also, there are many ways to free a malloced object in C programs.  You might 
have to decrement a reference count, you might have to first free any objects 
it contains pointers to, you might call a library-specific free routine 
called 'xfree', you might call a type-specific freeing routine or you might 
just call free.

For all these reasons, Haskell's garbage collector cannot just call 'free' for 
you.

 AFAICT this is how the pointer types behave:
   Ptr : freed when no longer used/referenced

No.

If it needs freed, you have to explicitly deallocate this by calling an 
appropriate routine.
This effectively means that you use Ptr for things accessed inside the IO 
monad.

   ForeignPtr : like Ptr, but will also run a finaliser when freed

Yes.  The finalizer is (a pointer to) any C function you like.
ForeignPtr is especially useful for datatypes accessed outside the IO monad.  
e.g., if you wanted to use a complex number library, you might use ForeignPtr 
for the freeing function.
ForeignPtr is also useful even if you are in the IO monad when you don't have 
a simple access pattern like 'allocate; use; free;'.

Note that the ffi libraries provide functions called 'malloc' and 'free' and a 
finalizer called 'finalizerFree'.  It is tempting to think that these are the 
C library 'malloc'/'free' and (a pointer to) 'free'.  This is not necessarily 
so and you must take care that:

- you only use MarshallAlloc.free and MarshallAlloc.finalizerFree with
  memory allocated using MarshallAlloc.malloc

- you only use libc's 'free' with memory allocated using libc's 'malloc'.

   StablePtr : not freed or collected

Yes.  StablePtrs are in a different category because they are pointers from C 
into Haskell (in contrast, Ptrs and ForeignPtrs are pointers from Haskell 
into C).  Since C doesn't have garbage collection, it is up to your C code to 
explicitly call 'freeStablePtr'. 

 (I haven't tested this; I've only read the FFI spec.)

I had a quick reread of sections 5.4 and 5.5 and I think your confusion is 
understandable.  It doesn't say anything about deallocation so you might 
plausibly guess that the story is the same as for Int8 (say) which also says 
nothing about deallocation.  ForeignPtrs are contrasted with Ptrs but only in 
whether or not they have finalizers.

I think the ffi spec has now been finalized so it's too late to fix this but 
perhaps the next revision could include the following wording (inserted after 
the first sentence of section 5.4).

  Objects of type 'Ptr a' and 'FunPtr a' are garbage collected
  in the normal way but the objects they _point to_ are not garbage
  collected.   If the objects pointed to require deallocation, this
  must be done by explicitly calling an appropriate function such as
  the C library function 'free'.

I have put some of the above in my FFI guide at:

  http://www.reid-consulting-uk.ltd.uk/docs/ffi.html

--
Alastair Reid www.haskell-consulting.com



___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Generating setMember functions for record structures

2003-09-23 Thread Malcolm Wallace
Peter Simons [EMAIL PROTECTED] writes:


  setFoo:: State - [Int] - State
  setFoo st x= State { foo = x
 , bar = bar st
 }

There is an easier way to do this, using the record update syntax
rather than record construction syntax.  e.g.

setFoo st x= st { foo = x }

All the unmentioned fields retain their previous values from the
'st' structure.

Regards,
Malcolm
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Database interface - would like advice on oracle library binding

2003-09-23 Thread Bayley, Alistair
(2nd attempt; mailman thinks I'm not a list member, but it still keeps
sending me mail.)

Still making slow progress on an Oracle database binding... now I'm trying
to fit the API I have into some sort of abstract interface (like the one(s)
discussed previously:
 http://haskell.org/pipermail/haskell-cafe/2003-August/004957.html ).


1. Is the left-fold the best/only interface to expose? I think yes, but that
doesn't allow fine-grained control over cursors i.e. being able to open many
cursors at once and interleave fetches from them. Or does it?


2. I'm finding it hard to write a doQuery function that takes an extraction
function that isn't a pig to write. Some advice would be useful here... (and
a long-ish explanation follows):

The Oracle Call Interface (OCI) requires that I allocate buffers for the
result of a single row fetch, before the first row is fetched. So a query
involves:
 - prepare statement etc
 - allocate buffers (one for each column - call OCI C function
DefineByPos)
 - fetch row
 - extract/marshal data from buffer into Haskell types (which are then
processed by fold function)
 - fetch, marshal (repeat until no more rows)
 - free buffers

i.e. the same buffers are re-used for each row.

The problem for me is how to specify the left-fold function in terms of the
low-level API. If I want to supply extraction functions (to extract Haskell
values from result buffer), how do I manage the buffer allocation in the
doQuery function? The buffer allocate/free code also needs to know the
column positions and types, in the same manner as the extract functions.

I want to be able to write code like this:

results - doQuery dbconn sqltext [] \row results - do
name- stringv row 1
address - stringv row 2
return (name,address):results

.. where the stringv function extracts/marshals a Haskell String from the
result buffer.

The intermediate approach I currently have means I have to pass an IO action
into the doQuery function that, when evaluated, allocates the buffer and
returns two more actions:
 - an action that extracts the row as a tuple
 - another action that frees the buffer

The doQuery function evaluates the initial action (to allocate the buffer),
uses the extract action to build the result (at present a list), and when
there are no more rows, uses the free action to free the buffer.

This approach is quite awkward (especially w.r.t. writing extract
functions), and it's hard for me to see how to build a better interface.
Hard, because of the memory management requirements.



Here's a chunk of the code. A lot of it is OCI plumbing, but I hope you can
see how awkward it is to create an extract function (see ex3 at the bottom).

Given pointers to the buffer, extract a string of variable length (you have
to terminate it yourself).

 fetchStringVal :: OCIColInfo - IO String
 fetchStringVal (_, bufptr, nullindptr, retsizeptr) = do
   retsize - liftM cShort2Int (peek retsizeptr)
   nullind - liftM cShort2Int (peek nullindptr) -- unused
   pokeByteOff (castPtr bufptr) retsize nullByte
   val - peekCString (castPtr bufptr)
   return val

Free a single column's buffer.

 freeColBuffer :: OCIColInfo - IO ()
 freeColBuffer (_, bufptr, nullindptr, retsizeptr) = do
   free bufptr
   free retsizeptr
   free nullindptr

Create a buffer for a string column, and return the extract and free IO
actions.

 getExtractFnString :: Int - ErrorHandle - StmtHandle - IO (IO String,
IO ())
 getExtractFnString posn err stmt = do
   c - defineCol err stmt posn 2000 oci_SQLT_CHR
   return ((fetchStringVal c), (freeColBuffer c))


doQuery uses the extractFns action to create the result buffer,
and the two actions (extract and free) which are passed to doQuery2.

 doQuery2 :: ErrorHandle - StmtHandle - IO a - IO () - [a] - IO [a]
 doQuery2 err stmt extractData freeMem results = do
   rc - fetch err stmt
   if rc == oci_NO_DATA
 then do
   freeMem
   return results
 else do
   v - extractData
   doQuery2 err stmt extractData freeMem (v:results)

 doQuery :: Session - String - (ErrorHandle - StmtHandle - IO (IO a, IO
())) - IO [a]
 doQuery (Sess env err con) qry extractFns = do
   stmt - getStmt env err
   prepare err stmt qry
   execute err con stmt
   (extractData, freeMem) - extractFns err stmt
   doQuery2 err stmt extractData freeMem []


The interface provided by doQuery means I have to write extract functions
like this.
Here's one for a select that returns three String columns.
It's quite awkward...

 ex3 :: ErrorHandle - StmtHandle - IO (IO (String, String, String), IO
())
 ex3 err stmt = do
   (fetchcol1, freecol1) - getExtractFnString 1 err stmt
   (fetchcol2, freecol2) - getExtractFnString 2 err stmt
   (fetchcol3, freecol3) - getExtractFnString 3 err stmt
   return
 ( do { s1 - fetchcol1; s2 - fetchcol2; s3 - fetchcol3; return (s1,
s2, s3) }
 , do { freecol1; freecol2; freecol3 }
 )



Database interface - would like advice on oracle library binding

2003-09-23 Thread Tom Pledger
Bayley, Alistair writes:
 :
 | Still making slow progress on an Oracle database binding... now I'm trying
 | to fit the API I have into some sort of abstract interface (like the one(s)
 | discussed previously:
 |  http://haskell.org/pipermail/haskell-cafe/2003-August/004957.html ).
 | 
 | 
 | 1. Is the left-fold the best/only interface to expose? I think yes,
 | but that doesn't allow fine-grained control over cursors i.e. being
 | able to open many cursors at once and interleave fetches from
 | them. Or does it?

It looks like the interleaving would be limited to a nested loop
structure: a cursor could be processed in full during one extraction
for another cursor.

Application-side nested loop structures are often a poor substitute
for server-side joins.

 | 2. I'm finding it hard to write a doQuery function that takes an
 | extraction function that isn't a pig to write. Some advice would be
 | useful here... (and a long-ish explanation follows):
 :

Here's my attempt to summarise the piggishness you describe:

The interface to Oracle requires that you initialise a cursor by
allocating a suitably typed buffer for each column prior to
fetching the first row, and finalise a cursor by freeing those
buffers after fetching the last row.

This means that we must iterate over the columns 3 times.  We
would prefer to express this iteration only once, and have the
other 2 happen automatically within the library.  (As opposed to
what ex3 does, which is to iterate for getExtractFnString, iterate
for fetchcolN, and iterate for freecolN.)

Here's one approach: find the OCI equivalent of JDBC's
ResultSetMetaData, and use it to drive the allocation and freeing of
buffers.

Here's another:

Add a mode attribute to the abstract data type which encompasses
ErrorHandle and StmtHandle.  (I'll persist in referring to that
ADT as Cursor.)

Expect extraction functions to be written along these lines:

\cursor result
   - do field1 - getIntcursor
 field2 - getString cursor
 field3 - getString cursor
 return ((field1, field2, field3):result, True)

Make getInt (and friends) behave differently depending on the mode
of the cursor they're passed: either allocate a buffer and return
_|_, decode and return the current column of the current row, or
free a buffer and return _|_.

doQuery could then apply the extraction function once in Allocate
mode after opening the cursor, once per fetched row in Decode
mode, and once in Free mode at the end.

There's nothing to stop an extraction function from varying the number
of get___ functions it applies, or trying to match their results when
not in Decode mode.  These weakness could be mitigated by:

Pointing out that some database connection standards (JDBC, and
for all I know also ODBC) don't guarantee that you can still get
at a row's 1st column after you've looked at its 2nd column,
i.e. there's a precedent for such fragility.

Complicating the extraction functions by giving them the type

(Cursor - b - IO (IO (b, Bool)))

, expecting that all the get___ functions are applied in the outer
IO layer, and undertaking that the inner IO layer will only be
used in Decode mode.

Regards,
Tom

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe