Re: Constant space infinite itteration ... solution?

2002-12-13 Thread Jan Kort


[EMAIL PROTECTED] wrote:


Also ... I've been using the graphics libs with HUGS,
but I can't find the equivalent in GHC ... what is
the recomended library for writing GUIs in GHC Haskell?
And where do I get it?
 


My current favourite way to make GUI's is to use the GUI
painter Glade and have it generate C code with calls to the Gtk
GUI library, after that the only thing you have to implement are
the callbacks. One big advantage Gtk offers over other GUI
libraries is that it clearly separates the GUI construction
code from the callback code, this makes it very suitable for GUI
painters, i.e. the code the GUI painter generates doesn't have
to be changed manually. Another advantage of Gtk, from the
Haskell viewpoint, is that it was designed to work with other
languages. Quoted from the Gtk page:

GTK+ has been designed from the ground up to support a range of 
languages, not only C/C++. Using GTK+ from languages such as Perl and 
Python (especially in combination with the Glade GUI builder) provides 
an effective method of rapid application development.

Although I haven't looked at the Haskell side in a while, everything
to go from Glade to a Haskell GUI should all be there:

http://www.gtk.org/
http://glade.gnome.org/
http://www.cse.unsw.edu.au/~chak/haskell/gtk/

The most recent version of Gtk+HS has support for libglade,
this means you can directly read the Glade XML file that
describes the GUI construction and the names of the
callback functions. To be honest I don't know how the
callbacks are actually connected to Haskell code, but there is
probably an example in the Gtk+HS distribution to show how
it works.

 Jan


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


Re: Floats and Doubles

2002-11-13 Thread Jan Kort

Juan Ignacio Garcia Garcia wrote:
 *P2 (fromRational ((toRational 4) - ( toRational 5.2 )))
 -1.2002

I can't explain this one, how would fromRational
know that it has to create a Double ?

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



Re: Using the Parsec library

2002-09-10 Thread Jan Kort

Jose Romildo Malaquias wrote:
 Any sugestion on how to implement the 'not starting with
 A: or B:' problem?
 

Hi,

I'm not familiar with Parsec, but in ParseLib it's
fairly straightforward, first you add a new combinator:

ifnot :: Parser a - Parser b - Parser b
ifnot (P p1) (P p2) =
 P ( \s - if parseOk (p1 s) then []
 else p2 s
   )
  where
parseOk :: [(a,String)] - Bool
parseOk [x] = True
parseOk _   = False

then you can say:

  ifnot parse_a_or_b parse_foo

You will need the sources of ParseLib to try it out
though, because P isn't exported.


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



Re: Beginner's question: Memo functions in Haskell

2002-06-05 Thread Jan Kort

Janis Voigtlaender wrote:
 
 It would also seem that one needs to write
 
  fast = memo slow
 
 instead, because otherwise a new memo-version of slow might be created
 for every call with some n (subject to let-floating?).
 However, the version:
 
   module Fib where
 
   import Memo
 
   slow 0 = 0
   slow 1 = 1
   slow n = fast (n-1) + fast (n-2)
 
   fast = memo slow
 
 is not particularly fast easier. Quite in contrary... strange.
 
 Janis.
 

It works under hugs98, but not under ghc5.02.2,
I CC'd the ghc bugs list.

Actually, I was also expecting fast n = memo slow n
to work ?

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



Re: sharing datatypes : best practice ?

2001-05-11 Thread Jan Kort

Taesch, Luc wrote:
 
 do u isolate just the datatype, or a few related with, in a very small file (header 
like, i would say)
 or some basic accessor function with it ?
 
 isnt it leading to massiv quantities of small files ?

Asuming you have some typed AST with many mutually recursive
datatypes, I would keep them in one big file. This should be
fine if the datatypes are simple (no deriving Read and Show
etc.).
For an AST you don't want accessor functions: the datatypes
are the interface. For some datatypes you want to hide
the datatype and provide a function based interface, this
should be in the same file as the datatype.
Usually there is also some kind of asumed hierarchy in
datatypes, e.g. Int  List  FiniteMap, to determine where
functions operating on multiple datatypes should be
placed, but that's the same in OO.

  Jan

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



Re: failed when trying to compile FranTk with ghc

2001-04-09 Thread Jan Kort

luc wrote:
 
 I tried FranTk with ghc 4.08 and got :
 (this is the "fixed" FrankTk, alledged working with 4.06, if im not
 wrong)
 
 are there any difference with 4.06  and 4.08 ?

Below is a list of fixes to get FranTk working with ghc4.08.

  Jan

Run configure like normal, i.e.:
./configure --prefix=/scratch/kort/pkgs/frantk

Change the file FranTk/src/FranSrc/Compatibility.ghc.hs to

-- this module is for GHC; GSL
module Compatibility
   ( double2Float
   , yield
   , debugMsgLn
   , setDebug
   , mkWeakIORef
   , toInt
   , fromInt
   ) where
import GlaExts 
import NumExts(doubleToFloat)
import PrelRead(readDec)
import IOExts
import Concurrent
import Exception

double2Float = doubleToFloat

setDebug :: Bool - IO ()
setDebug _ = return ()

debugMsgLn :: String - IO ()
debugMsgLn s = assert (trace s `seq` True) $ return () 


In the file FranTk/src/FranTkSrc/Makefile change the line:
HC_OPTS+= -i../FranSrc:../TclHaskellSrc -fallow-overlapping-instances 
-fallow-undecidable-instances
-syslib misc 
to:
HC_OPTS+= -i../FranSrc:../TclHaskellSrc -fallow-overlapping-instances 
-fallow-undecidable-instances
-syslib data

In the file FranTk/demos/Makefile change the line:
HC_OPTS+= -i../src/FranTkSrc:../src/FranSrc:../src/TclHaskellSrc 
-fallow-overlapping-instances
-fallow-undecidable-instances -syslib misc
to:
HC_OPTS+= -i../src/FranTkSrc:../src/FranSrc:../src/TclHaskellSrc 
-fallow-overlapping-instances
-fallow-undecidable-instances -syslib data

If the compiler complains about not finding the file "tcl.h", in the
file FranTk/src/TclHaskellSrc/Makefile change the rule:
tclhaskell.o: tclhaskell.c tclhaskell.h
$(HC) -c tclhaskell.c
to:
tclhaskell.o: tclhaskell.c tclhaskell.h
$(HC) -I/opt/arch/lib/tk8.3/include -c tclhaskell.c
where /opt/arch... is the place "tcl.h" and "tk.h" are.

In the directory FranTk/src/TclHaskellSrc do:
rm *.hi *.o

In the file FranTk/src/TclHaskellSrc/Makefile add TclPrim.hs to
the HS_SRCS list.

In the directory FranTk/src/FranSrc do:
rm *.hi

In the directory FranTk/demos do:
rm *.hi

And then continue the normal installation with:
gmake boot
gmake all

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



Re: Bagley shootout. Was: Lightningspeed haskell

2001-03-06 Thread Jan Kort


I implemented the programs for hash1 and hash2, but I had to
make a lot of changes to FiniteMap to get them to work:
- I changed foldl to foldl' (as defined in Hugs).
- I made foldFM strict (like foldl').
- I made the datatype FiniteMap strict (put !'s everywhere).
I put the programs below, maybe there is a better way to do this.

  Jan

-- Hash1
module Main(main) where

import FiniteMap
import System

writeHex' :: Int - String
writeHex' 0 = ""
writeHex' n
  = c:writeHex' y
where
  x = n `mod` 16
  y = n `div` 16
  c | x = 9= toEnum ((fromEnum '0') + x)
| otherwise = toEnum ((fromEnum 'A') + x - 10)

writeHex :: Int - String
writeHex n
  | n  0 = reverse (writeHex' n)
  | n == 0= "0"
  | otherwise = '-':(reverse (writeHex' (-n)))

main :: IO()
main = do {
[arg] - getArgs;
let
n  = read arg
fm = listToFM [(writeHex i,i) | i - [1..n]]
c  = sum [if elemFM (show i) fm then 1 else 0 | i - reverse [1..n]]
in
putStrLn (show c);



-- Hash2
module Main(main) where

import FiniteMap
import System
import Maybe

foldl'   :: (a - b - a) - a - [b] - a
foldl' _ a [] = a
foldl' f a (x:xs) = (foldl' f $! f a x) xs

f :: FiniteMap Int Int - FiniteMap Int Int - Int - FiniteMap Int Int
f hash1 hash2 k
  | isJust elt2 = addToFM hash2 k (fromJust elt1 + fromJust elt2)
  | otherwise   = addToFM hash2 k (fromJust elt1)
where
  elt1 = lookupFM hash1 k
  elt2 = lookupFM hash2 k

main :: IO()
main = do {
[arg] - getArgs;
let
n   = read arg
hash1   = listToFM [(i,i) | i - [1..1]]
keys= concat (take n (repeat (keysFM hash1)))
hash2   = foldl' (f hash1) emptyFM keys;
h1_1= fromJust (lookupFM hash1 1)
h1_ = fromJust (lookupFM hash1 )
h2_1= fromJust (lookupFM hash2 1)
h2_ = fromJust (lookupFM hash2 )
in
putStrLn (show h1_1 ++ " " ++ show h1_ ++ " " ++
  show h2_1 ++ " " ++ show h2_);
}

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



Re: Bagley shootout. Was: Lightningspeed haskell

2001-03-02 Thread Jan Kort

Simon Peyton-Jones wrote:
 
 A String is a [Char] and a Char is a heap object. So
 a file represented as a string takes a massive 20 bytes/char
 (12 for the cons cell, 8 for the Char cell).  Then it's all sucked
 through several functions.
 
 It's entirely possible, though, that the biggest performance hit
 is in the I/O itself.  We'd be happy if anyone wanted to invesigate
 and improve.

Unless ghc is extremely fast at filling a heap, it's the memory
allocation. I get 11.8 seconds for ghc with a standard heap and
7.3 seconds when I give it enough heap not to do garbage collection.
Since this is 200M, I don't think there is much time to do
anything else.
The input is 200 bytes. So, this would be 40M worth of [Char]
data, I guess lines and unlines make ehm 12*2*2=48M, so that's
about 100M total. I guess the other 100M is used for function
applications.

  Jan

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



Re: framework for composing monads?

2001-02-15 Thread Jan Kort


Andy Gill's Monad Template Library is good for that, but the link
from the Haskell library page is broken:

  http://www.cse.ogi.edu/~andy/monads/doc.htm

  Jan

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



Re: Floating point performance

2001-01-29 Thread Jan Kort

"Julian Seward (Intl Vendor)" wrote:
 
 I tried this, with ghc-4.08.1 -O both with and without
 profiling, on a Sparc box of I believe around 300 MHz,
 and I can't reproduce it at all.  Without profiling,
 it allocates about 505 k of heap and runs in 0.02
 seconds.
 
 Ummm ?
 
 J

I didn't use any optimizations, but I am sure that
passing -O to ghc will make it see that 1*1*... is a
constant expression. I guess turning all optimizations
off is not the right way to test stuff either.

  Jan

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



Floating point performance

2001-01-26 Thread Jan Kort

Hi,
I noticed ghc (version 4.08.1) floating point performance is
really slow on my computer: a 270Mhz sun ultra5. The program
below does 1 milion floating point multiplications and takes
2 seconds to run. I made a profile and it says most of the
time (93%) is spent in the function bar. Any idea what is
going on ?

Regards,
  Jan

module Main where

foo :: Double - [Double]
foo 0 = [1]
foo n = bar n:foo (n-1)

bar :: Double - Double
bar n = n*1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1
 *1*1*1*1*1*1*1*1*1*1

foldl'   :: (a - b - a) - a - [b] - a
foldl' _ a [] = a
foldl' f a (x:xs) = (foldl' f $! f a x) xs

main :: IO()
main = putStrLn (show (foldl' (+) 0 (foo 1)))

---
Profile:

total time  =2.60 secs   (130 ticks @ 20 ms)
total alloc =  24,845,828 bytes  (excludes profiling overheads)

COST CENTRE  MODULE %time %alloc

bar  Main93.1   96.1
foo  Main 3.12.4
foldl'   Main 3.11.4


  individual inherited
COST CENTRE  MODULE entries  %time %alloc   %time %alloc

MAIN MAIN 00.0   0.0100.0 100.0
 mainMain 00.0   0.0  0.0   0.0
 CAF PrelShow 10.0   0.0  0.0   0.0
 CAF PrelFloat30.0   0.0  0.0   0.0
 CAF PrelHandle   30.0   0.0  0.0   0.0
 CAF Main 90.0   0.0100.0 100.0
  main   Main 10.8   0.0100.0 100.0
   foo   Main 100013.1   2.4 96.2  98.5
bar  Main 1   93.1  96.1 93.1  96.1
   foldl'Main 100023.1   1.4  3.1   1.4

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



Re: C stack

2000-12-15 Thread Jan Kort

Simon Marlow wrote:
 
 I don't forsee any problems with the C stack - the stack pointer stays
 static during execution of Haskell code, and only moves when we do a C
 call or return to the RTS.

But how do I get the address of the bottom of the stack ? It seems I can
define a C main so I can get the bottom of the stack, but how do I make
it call Haskell's main to start the application ?

 
 Don't forget to tell the GC to traverse the Haskell heap too - GHC keeps
 this in mmapped address space.  See fptools/ghc/rts/MBlock.c for the
 details.

Ok, I will do that, it looks like a better idea than working with
ForeignObj and finalizers.

  Jan

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



C stack

2000-12-14 Thread Jan Kort

Hi,

I'm trying to write an interface for a C library that
uses a Boehm type garbage collector. So, I need to get
the address of the bottom of the C stack. In a C
application this would look something like:
  main()
  {
int bottomOfStack;
  }
Where "bottomOfStack" would be the thing I need. So,
I'd want some function like:
  bottomOfStack :: IO Addr

Would it be possible at all to make an interface to
a C library that uses Boehm's garbage collection ?
What Boehm's algorithm does is traverse the C stack
at each garbage collect marking all accessible
nodes and then sweeping all unmarked nodes. Would
this cause problems with the C code generated by
ghc ?

  Jan

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



Re: openFile, process file table full

2000-09-12 Thread Jan Kort

Simon Marlow wrote:
 
  Arguably, readFile is too strict: why is the file opened, if there
  aren't any characters needed. What is the motivation for opening the
  file eagerly?
 
 Once we've started reading lazilly, it's hard to generate errors.  The file
 is opened eagerly so that any errors generated (such as if the file doesn't
 exist) can be propogated immediately to the caller.
 
 I checked the Haskell Report, which doesn't seem to specify the correct
 behaviour - I guess this should be clarified.  The report also contains the
 sentence "The exceptions raised by the I/O functions in the Prelude are
 defined in the Library Report", but I can't find any reference to
 readFile/writeFile in the library report.
 
 Cheers,
 Simon

I can't seem to work around this behaviour, is it possible to
force readFile to just open a file, read it entirely and close it
before doing the next open ? I tried a few things with seq,
but this doesn't work:

xs - mapM (\x - let y = readFile x
  in seq y y) (take 1000 (repeat "tmp"));

and neither does this:

let
  f = mapM (\x - let y = readFile x
  in seq y y) (take 1000 (repeat "tmp"));
in do {
xs - seq f f;
return ();
}

  Jan




openFile, process file table full

2000-09-08 Thread Jan Kort

Hi,

The following program:

module Main(main) where
main:: IO()
main = do {
xs - mapM readFile (take 1000 (repeat "tmp"));
return ();
}

Results in the error:

Fail: resource exhausted
Action: openFile
Reason: process file table full tmp



This doesn't work either:

myreadFile :: String - IO String
myreadFile filename = do {
f - openFile filename ReadMode;
x - hGetContents f;
hFlush f;
hClose f;
return x;
}

main:: IO()
main = do {
xs - mapM (\x - let y = myreadFile x in seq y y)
   (take 1000 (repeat "tmp"));
return ();
}

Regards,
  Jan

P.S. My system:

(~ 270) uname -sr
SunOS 5.6
(~ 271) dmesg | grep SUNW
cpu0: SUNW,UltraSPARC-IIi (upaid 0 impl 0x12 ver 0x12 clock 270 MHz)
SUNW,m64B0 is /pci@1f,0/pci@1,1/SUNW,m64B@2
stdout is /pci@1f,0/pci@1,1/SUNW,m64B@2 major 35 minor 0
SUNW,hme0: CheerIO 2.0 (Rev Id = c1) Found
SUNW,hme0 is /pci@1f,0/pci@1,1/network@1,1
SUNW,hme0: Using Internal Transceiver
SUNW,hme0: 100 Mbps full-duplex Link Up
(~ 272) cat /etc/release 
  Solaris 2.6 5/98 s297s_hw3smccDesktop_09 SPARC
   Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
   Assembled on 24 April 1998
(~ 273) ghc --version
The Glorious Glasgow Haskell Compilation System, version 4.08
(~ 274) gcc --version
2.8.1
(~ 275) which make
make:aliased to gmake
(~ 276) /home/kort/pkgs/make/bin/make --version
GNU Make version 3.78.1, by Richard Stallman and Roland McGrath.
Built for sparc-sun-solaris2.6
Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

Report bugs to [EMAIL PROTECTED].

(~ 277) man X | grep 'X Version' | grep '  1$'
Reformatting page.  Wait... done
X Version 11 Last change: Release 6 1




compiled program loops

2000-04-08 Thread Jan Kort

I compiled a program using ghc version 4.06 and it goes into a loop, I
tried
figuring out what goes on with "trace", but it looks as if this is a ghc
bug. Wether it loops or not depends on the length of the list: if you
remove
1 "Int 1" line in the code below it will finish immediatly.

I need a fix urgently, I can't find any way to work around this problem
in
the example program, let alone in the real application.

In the real application I also get the error:
bingraph: fatal error: evacuate: THUNK_SELECTOR: strange selectee 27
which I'm hoping is related, because I have no idea what it means and
I can't reproduce this in an example program. Any idea where I should
be looking for the cause of this ?

  Jan


My system:
(~/src/haskell/bgtmp 54) uname -sr
SunOS 5.6
(~/src/haskell/bgtmp 55) dmesg | grep SUNW
cpu0: SUNW,UltraSPARC-IIi (upaid 0 impl 0x12 ver 0x91 clock 360 MHz)
SUNW,m64B0 is /pci@1f,0/pci@1,1/SUNW,m64B@2
stdout is /pci@1f,0/pci@1,1/SUNW,m64B@2 major 35 minor 0
SUNW,hme0: CheerIO 2.0 (Rev Id = c1) Found
SUNW,hme0 is /pci@1f,0/pci@1,1/network@1,1
SUNW,hme0: Using Internal Transceiver
SUNW,hme0: 100 Mbps full-duplex Link Up
(~/src/haskell/bgtmp 56) cat /etc/release 
  Solaris 2.6 5/98 s297s_hw3smccDesktop_09 SPARC
   Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
   Assembled on 24 April 1998
(~/src/haskell/bgtmp 57) ghc --version
The Glorious Glasgow Haskell Compilation System, version 4.06
(~/src/haskell/bgtmp 58) gcc --version
egcs-2.91.66


The program:
module Main where
import GlaExts

data ATerm = AList [ATerm]
   | AInt Integer
-- deriving (Show,Read)

toNode (AList xs) = sum (map toNode xs)
toNode (AInt x) = x

-- Main.
--
main :: IO()
main = do {
let
aterm = trace "test1" (trace "test22" (AList (trace "test23" [
trace "test24" (AInt 1),
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 1,
AInt 

Re: records in Haskell

2000-03-16 Thread Jan Kort

Simon Marlow wrote:
 
 Jan Kort writes:
 
  It seem that any record, no matter how trivial, can't be much
  longer than about 200 lines in Haskell. If a try to compile a
  300 line record containing just:
  data X = X {
  f1 :: String,
  f2 :: String,
  f3 :: String,
...
f300 :: String
  }
  It needs about 90M heap in ghc4.06. Whereas a 150 line record
  requires less than 6M heap. After this big gap it levels off
  to a somewhat more decent exponential increase: a 450 line
  record requires about 180M heap.
 
  I could file a bug report, but it seems that all compilers
  (ghc4.06, nhc98, hbc0.9994 and hugs) have this problem. So,
  is this a fundamental problem ?
 
 Actually, the 150-line record needs about 20M, and the 300-line record needs
 about 75M.  These figures are roughly double the actual residency, because
 GHC's underlying collector is a copying, not compacting, one.
 
 GHC automatically increases the heap size up to a maximum of 64M unless you
 tell it not to (with -optCrts-M32m, for example).  I'll bet this is the
 source of the confusion.
 
 The heap requirement is still non-linear, but I'm guessing that this is
 because for each line you add to the record the compiler has to not only
 generate a new selector function, but also add a field to the record being
 pattern matched against in all the existing selectors.
 
 Cheers,
 Simon


Thanks for the answers and sorry for the late reaction.

I worked out an example to understand what you wrote.
GHC will probably generate something like this:

data R = R String Integer
 deriving (Read,Show)

selectA (R s _) = s
selectB (R _ i) = i

updateA (R _ b) a = (R a b)
updateB (R a _) b = (R a b)

emptyR  = R undefined undefined

Which you can then use like this:

updateR = updateB (updateA emptyR "a") 2
testA   = selectA updateR
testB   = selectB updateR

I agree that the select and update pattern matchings would
get big for a 300 line record, but 75M is a lot of memory.
Especialy because the pattern matches and the right hand
sides of both the selects and updates are trivial pieces
of code: no nesting, no currying etc. But maybe GHC
generates something extra ? Is special code generated
for updating multiple fields for example ?

I can probably work around this in a simple way: since I'm
generating the big record, I might as well generate
the selects, updates and emptyR instead and split them
over a couple of files.

  Jan



deriving Read and Show

2000-02-22 Thread Jan Kort

Hi,

When I use deriving Read and Show on many datatypes,
both ghc and hugs don't work.
I've attached an example, to get the error, do:
hugs Main.hs
or:
ghc Main.hs
Hugs quits with the error message:
ERROR "Main.hs": Type constructor storage space exhausted
And ghc quits with:
GHC's heap exhausted;
while trying to allocate 0 bytes in a 67108864-byte heap;
use the `-Hsize' option to increase the total heap size.

It's not urgent though, I can work around it.

I use Hugs98 and my setup for ghc is:
(~/project/genast 76) uname -sr
SunOS 5.6
(~/project/genast 77) dmesg | grep SUNW
cpu0: SUNW,UltraSPARC-IIi (upaid 0 impl 0x12 ver 0x12 clock 270 MHz)
SUNW,m64B0 is /pci@1f,0/pci@1,1/SUNW,m64B@2
stdout is /pci@1f,0/pci@1,1/SUNW,m64B@2 major 35 minor 0
SUNW,hme0: CheerIO 2.0 (Rev Id = c1) Found
SUNW,hme0 is /pci@1f,0/pci@1,1/network@1,1
SUNW,hme0: Using Internal Transceiver
SUNW,hme0: 100 Mbps full-duplex Link Up
(~/project/genast 78) cat /etc/release 
  Solaris 2.6 5/98 s297s_hw3smccDesktop_09 SPARC
   Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
   Assembled on 24 April 1998
(~/project/genast 79) ghc --version
The Glorious Glasgow Haskell Compilation System, version 4.06
(~/project/genast 80) gcc --version
egcs-2.91.66
(~/project/genast 81) 

  Jan

module Main(main) where

data X1 = X1 String deriving (Read,Show)
data X2 = X2 String deriving (Read,Show)
data X3 = X3 String deriving (Read,Show)
data X4 = X4 String deriving (Read,Show)
data X5 = X5 String deriving (Read,Show)
data X6 = X6 String deriving (Read,Show)
data X7 = X7 String deriving (Read,Show)
data X8 = X8 String deriving (Read,Show)
data X9 = X9 String deriving (Read,Show)
data X10 = X10 String deriving (Read,Show)
data X11 = X11 String deriving (Read,Show)
data X12 = X12 String deriving (Read,Show)
data X13 = X13 String deriving (Read,Show)
data X14 = X14 String deriving (Read,Show)
data X15 = X15 String deriving (Read,Show)
data X16 = X16 String deriving (Read,Show)
data X17 = X17 String deriving (Read,Show)
data X18 = X18 String deriving (Read,Show)
data X19 = X19 String deriving (Read,Show)
data X20 = X20 String deriving (Read,Show)
data X21 = X21 String deriving (Read,Show)
data X22 = X22 String deriving (Read,Show)
data X23 = X23 String deriving (Read,Show)
data X24 = X24 String deriving (Read,Show)
data X25 = X25 String deriving (Read,Show)
data X26 = X26 String deriving (Read,Show)
data X27 = X27 String deriving (Read,Show)
data X28 = X28 String deriving (Read,Show)
data X29 = X29 String deriving (Read,Show)
data X30 = X30 String deriving (Read,Show)
data X31 = X31 String deriving (Read,Show)
data X32 = X32 String deriving (Read,Show)
data X33 = X33 String deriving (Read,Show)
data X34 = X34 String deriving (Read,Show)
data X35 = X35 String deriving (Read,Show)
data X36 = X36 String deriving (Read,Show)
data X37 = X37 String deriving (Read,Show)
data X38 = X38 String deriving (Read,Show)
data X39 = X39 String deriving (Read,Show)
data X40 = X40 String deriving (Read,Show)
data X41 = X41 String deriving (Read,Show)
data X42 = X42 String deriving (Read,Show)
data X43 = X43 String deriving (Read,Show)
data X44 = X44 String deriving (Read,Show)
data X45 = X45 String deriving (Read,Show)
data X46 = X46 String deriving (Read,Show)
data X47 = X47 String deriving (Read,Show)
data X48 = X48 String deriving (Read,Show)
data X49 = X49 String deriving (Read,Show)
data X50 = X50 String deriving (Read,Show)
data X51 = X51 String deriving (Read,Show)
data X52 = X52 String deriving (Read,Show)
data X53 = X53 String deriving (Read,Show)
data X54 = X54 String deriving (Read,Show)
data X55 = X55 String deriving (Read,Show)
data X56 = X56 String deriving (Read,Show)
data X57 = X57 String deriving (Read,Show)
data X58 = X58 String deriving (Read,Show)
data X59 = X59 String deriving (Read,Show)
data X60 = X60 String deriving (Read,Show)
data X61 = X61 String deriving (Read,Show)
data X62 = X62 String deriving (Read,Show)
data X63 = X63 String deriving (Read,Show)
data X64 = X64 String deriving (Read,Show)
data X65 = X65 String deriving (Read,Show)
data X66 = X66 String deriving (Read,Show)
data X67 = X67 String deriving (Read,Show)
data X68 = X68 String deriving (Read,Show)
data X69 = X69 String deriving (Read,Show)
data X70 = X70 String deriving (Read,Show)
data X71 = X71 String deriving (Read,Show)
data X72 = X72 String deriving (Read,Show)
data X73 = X73 String deriving (Read,Show)
data X74 = X74 String deriving (Read,Show)
data X75 = X75 String deriving (Read,Show)
data X76 = X76 String deriving (Read,Show)
data X77 = X77 String deriving (Read,Show)
data X78 = X78 String deriving (Read,Show)
data X79 = X79 String deriving (Read,Show)
data X80 = X80 String deriving (Read,Show)
data X81 = X81 String deriving (Read,Show)
data X82 = X82 String deriving (Read,Show)
data X83 = X83 String deriving (Read,Show)
data X84 = X84 String deriving (Read,Show)
data X85 = X85 String 

records in Haskell

2000-02-11 Thread Jan Kort

Hi,

It seem that any record, no matter how trivial, can't be much
longer than about 200 lines in Haskell. If a try to compile a
300 line record containing just:
data X = X {
f1 :: String,
f2 :: String,
f3 :: String,
...
f300 :: String
}
It needs about 90M heap in ghc4.06. Whereas a 150 line record
requires less than 6M heap. After this big gap it levels off
to a somewhat more decent exponential increase: a 450 line
record requires about 180M heap.

I could file a bug report, but it seems that all compilers
(ghc4.06, nhc98, hbc0.9994 and hugs) have this problem. So,
is this a fundamental problem ?

  Jan



FFI bug ?

2000-01-31 Thread Jan Kort

Hi,

It seems that FFI no longer accepts "ByteArray Int" in ghc 4.06 (it
does in ghc 4.04), it looks intentional ? If so, is there another
way to pass a String to a C function ? If not, I have attached
a small example, to see the result do:
 tar -xf abc.tar
 make
The result should be:
---
gcc -O2 -Wall-c -o at.o at.c
rm -f Main.o
ghc -O -fglasgow-exts -recomp -dcore-lint -fvia-C
-fallow-overlapping-instances -fallow-undecidable-instances -syslib
posix   -c Main.hs 

Main.hs:5:
Unacceptable argument type in foreign declaration: ByteArray Int
When checking declaration:
foreign import _ccall "c_test" h_test :: ByteArray Int - IO ()

Compilation had errors

make: *** [Main.o] Error 1
---

My configuration is:
(~/project/bug 88) uname -sr
SunOS 5.6
(~/project/bug 89) dmesg | grep SUNW
cpu0: SUNW,UltraSPARC-IIi (upaid 0 impl 0x12 ver 0x12 clock 270 MHz)
SUNW,m64B0 is /pci@1f,0/pci@1,1/SUNW,m64B@2
stdout is /pci@1f,0/pci@1,1/SUNW,m64B@2 major 35 minor 0
SUNW,hme0: CheerIO 2.0 (Rev Id = c1) Found
SUNW,hme0 is /pci@1f,0/pci@1,1/network@1,1
SUNW,hme0: Using Internal Transceiver
SUNW,hme0: 100 Mbps full-duplex Link Up
(~/project/bug 90) cat /etc/release 
  Solaris 2.6 5/98 s297s_hw3smccDesktop_09 SPARC
   Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
   Assembled on 24 April 1998
(~/project/bug 91) ghc --version
The Glorious Glasgow Haskell Compilation System, version 4.06
(~/project/bug 92) gcc --version
egcs-2.91.66
---

If this is a bug, there is no urgency in fixing it, ghc4.04 works
very good too.

Regards,
  Jan
 abc.tar


Re: drop take [was: fixing typos in Haskell-98]

2000-01-28 Thread Jan Kort

Marcin 'Qrczak' Kowalczyk wrote:
 My preference is still (B). (A) is not *very* bad, but should really
 replicate (-7) "foo" be []?

Mine too.

Actually after writing my own version of "drop" it turns out that
in my case n  0 is a programmer error and n  length xs a user error.
So what you end up with (if (B) is choosen) is something like:

bafDrop :: Int - String - String
bafDrop i xs | i  length xs = bafError "corrupt BAF file"
 | otherwise = drop i xs

Of course n  0 isn't always a programmer error and you might want
to overwrite it. So that would suggest (A), but right now (B) is my
favourite, because I can't think of a practical example where n  0
would be a user error.

Actually, (A) might be better, the extra check for i  0 is not
time consuming anyway. I guess flipping a coin to choose between
(A) and (B) would work just as well (provided this doesn't lead
to a discussion about what coin to use).

  Jan

P.S. Now that I see the "bafDrop" outside the code, it looks odd. I
 have no right claiming that the BAF -file- is corrupt at that
 point. I'll have to rewrite this using some exception Monad.
 Since this would make the code even bigger I might as well
 put the entire code of drop in it. So much for code reuse...



FFI on sparc

2000-01-24 Thread Jan Kort

Hi,

I'm using the FFI on a sparc. Everything works fine except
when I return a float or double from C to Haskell. My config is:

SunOS 5.6
cpu0: SUNW,UltraSPARC-IIi (upaid 0 impl 0x12 ver 0x12 clock 270 MHz)
SUNW,m64B0 is /pci@1f,0/pci@1,1/SUNW,m64B@2
stdout is /pci@1f,0/pci@1,1/SUNW,m64B@2 major 35 minor 0
SUNW,hme0: CheerIO 2.0 (Rev Id = c1) Found
SUNW,hme0 is /pci@1f,0/pci@1,1/network@1,1
SUNW,hme0: Using Internal Transceiver
SUNW,hme0: 100 Mbps full-duplex Link Up
  Solaris 2.6 5/98 s297s_hw3smccDesktop_09 SPARC
   Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
   Assembled on 24 April 1998
The Glorious Glasgow Haskell Compilation System, version 4.04,
patchlevel 1
egcs-2.91.66

The output of my program is:

check1 1.23
1.342972116e9
check2 1.23
1.07293442e9
check3 1.23
1.3429812e9

I've attached the tarred sources.

Regards,
  Jan
 abc.tar


prelude drop and take

2000-01-18 Thread Jan Kort

Hi,

This minor inconsistency has been bothering me for some time:

Prelude drop 10 "test"
""
Prelude drop (-1) ""
""
Prelude drop (-1) "a"
"
Program error: Prelude.drop: negative argument

I got these results from Hugs, but the code is identical to that
specified in the Haskell98 standard.

Why not an error for the negative argument on an empty list ?

Secondly, why not an error for an argument that's too big ? What
I would like is this:

drop 0 xs = xs
drop n (_:xs) | n0   = drop (n-1) xs
drop n _  | n0   = error "Prelude.drop: argument too big"
  | otherwise = error "Prelude.drop: negative argument"

Or is there a good reason for drop being able to drop more
elements than the list is long ? In which case I would like:

drop 0 xs= xs
drop n [] | n0  = []
drop n (_:xs) | n0  = drop (n-1) xs
drop _ _ = error "Prelude.drop: negative argument"

I doubt the second solution would be much less efficient. The first
solution should be just as efficient as the one in Haskell98.

The same goes for take and splitAt.

Regards,
  Jan



Re: bootstrapping ghc on AIX

1998-10-20 Thread Jan Kort

Sigbjorn Finne (Intl Vendor) wrote:
 
 Jan Kort [EMAIL PROTECTED] writes:
 
  Thanks, I can get a lot further now, everything apart from
  compiling the assembler files and linking the hsc works, but
  that will have to wait till tommorow :)
 
Jan
 
 
 Great, if you should get stuck while doing this, let us know,
 and we'll try to help out.
 
 --Sigbjorn

It looks like I'm either missing more code, or I'm on the wrong
track. I can't find the powerpc assembly code for "JMP_" (should
be in ghc/includes/TailCalls.h), "StgRun" (should be in
ghc/rts/StgCRun.c) and for "StgReturn" (should be in ghc/rts/StgRun.S).
I also tried to compile with USE_MINIINTERPRETER set to 1, but this
led to having to set INTERPRETER_ONLY to 1 as well,
otherwise Hugs_CONSTR_entry would be undefined. I asume that
"INTERPRETER_ONLY" means no compiler ?

In case I'm not missing code and I have to write it myself, if
I don't use native code generation, can I do:

#ifdef powerpc_TARGET_ARCH

StgThreadReturnCode
StgRun(StgFunPtr f) {
f();
return (StgThreadReturnCode)R1.i;
}

#endif

And for the "JMP_":

#if powerpc_TARGET_ARCH

#define JMP_(cont)  \
{   \
  goto (void *)(cont);  \
}

#endif powerpc_TARGET_ARCH

I don't know what to do about StgReturn in ghc/rts/StgRun.S,
judging from the ifdef, the StgReturn is only valid for 386
architectures, so where is it defined on a sparc or an alpha ?

-- 

Jan Kort



Re: bootstrapping ghc on AIX

1998-10-16 Thread Jan Kort

Hi,

  In ghc/Makefile it says:

17  # Order is important! driver/ has to come before includes/ which
18  # again has to come before the rest.
19  #
20  # If we're booting from .hc files, swap the order
21  # we descend into compiler/ and lib/
22  #
23  ifeq "$(GhcWithHscBuiltViaC)" "NO"
24  SUBDIRS = utils driver includes rts docs compiler lib
25  else
26  SUBDIRS = utils driver includes rts docs lib compiler
27  endif

Shouldn't this be 'ifeq "$(GhcWithHscBuiltViaC)" "YES"' ?

  Jan

-- 

Jan Kort



bootstrapping ghc on AIX

1998-10-16 Thread Jan Kort

Hi,

  I tried to bootstrap ghc4.00 on AIX with the "--enable-hc-boot"
flag, but I got an error:

RTS -K2m -H10m -RTS-g rename/ParseIface.y
make[2]: RTS: Command not found
make[2]: *** [rename/ParseIface.hs] Error 127
make[1]: *** [boot] Error 1
make: *** [boot] Error 1

It looks like the variable HAPPY in ghc/compiler/Makefile is not
defined, but since I'm bootstrapping I don't see why it would have
to be defined ?

Here are the commands I typed to produce the bug report,
which I have gzipped and attached (unfortunately netscape
attachments don't get through, so I'll send it as a seperate
mail after this one):

script myscript
uname -srv
gcc --version
make --version
tar -xf ghc-4.00-src.tar
cd fptools
./configure --enable-hc-boot
make boot
exit

I also tried to compile ghc2.10, but this gives the same error.

I can get "make boot" through by commenting out 6 lines related
to Happy and some dependencies in "ghc/compiler/Makefile". But the "make all"
does not get very far, the first thing it complains about is "etext"
being undefined in "ghc/includes/ClosureMacros.h", I changed to "_etext"
to "etext" in "ghc/includes/config.h". Then I added a line to
"ghc/rts/MBlock.c":
#define ASK_FOR_MEM_AT 0x5000
Then I copied the aix aix_TARGET_OS ifdef from "ghc/rts/PrimOps.hc" to
"ghc/includes/PrimOps.h".
The I got the following error:

make[4]: Leaving directory `/pluto/home/jan/fptools/ghc/rts/gmp/mpz'
../../ghc/driver/ghc  -I../includes -I. -Igum -optc-Wall  -optc-W
-optc-Wstrict-prototypes  -optc-Wmissing-proto
Assembler:
/tmp/ccHbwaUa.s: line 61: 1252-044 The specified source character 0xc does not have
meaning in the command context used.
/tmp/ccHbwaUa.s: line 61: 1252-142 Syntax error.
make[2]: *** [StgRun.o] Error 1
make[1]: *** [all] Error 1
make: *** [all] Error 1

I removed the assembler files from "ghc/rts/Makefile" (probably not a good
idea). Then I got the error:


==fptools== make all --no-print-directory -r;
 in /pluto/home/jan/ghc4/fptools/ghc/lib/std

make[3]: *** No rule to make target `Array.o', needed by `libHS.a'.  Stop.
make[2]: *** [all] Error 1
make[1]: *** [all] Error 1
make: *** [all] Error 1

Which I don't understand, am I missing some hc files ?

Regards,
  Jan

-- 

Jan Kort