----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 108

High again,

the build was successful ;-). Unfortunately, the first test program
which aims at stressing the new RTS dies with a fatal error. Here
is a transcript of the session ...

jod 76> uname -a
SunOS jod 5.6 Generic_105181-08 sun4u sparc SUNW,Ultra-1
jod 77> ghc -v EDigits.lhs
The Glorious Glasgow Haskell Compilation System, version 4.00, patchlevel 0

literate pre-processor:
	/home/III/a/ralf/FP/ghc/lib/unlit  EDigits.lhs -  >> /tmp/ghc25291.lpp

real        0.0
user        0.0
sys         0.0

Effective command line: -v

Ineffective C pre-processor:
	echo '{-# LINE 1 "EDigits.lhs" -}' > /tmp/ghc25291.cpp && cat /tmp/ghc25291.lpp >> /tmp/ghc25291.cpp

real        0.0
user        0.0
sys         0.0
ghc:compile:Output file EDigits.o doesn't exist
ghc:compile:Interface file EDigits.hi doesn't exist
ghc:recompile:Input file EDigits.lhs newer than EDigits.o

Haskell compiler:
	/home/III/a/ralf/FP/ghc/lib/hsc ,-W ,/tmp/ghc25291.cpp  -fignore-interface-pragmas -fomit-interface-pragmas -fsimplify [  -ffloat-lets-exposing-whnf -ffloat-primops-ok -fcase-of-case -fdo-case-elim -freuse-con -fpedantic-bottoms -fclone-binds -fmax-simplifier-iterations4  ]   -fwarn-overlapping-patterns -fwarn-missing-methods -fwarn-duplicate-exports -fhi-version=400 -himap=.%.hi:/home/III/a/ralf/FP/ghc/lib/imports/std%.hi   -v -hifile=/tmp/ghc25291.hi -S=/tmp/ghc25291.s -F= -FH= +RTS -H6000000 -K1000000
Glasgow Haskell Compiler, version 4.00, for Haskell 1.4

real        5.7
user        5.3
sys         0.2

Pin on Haskell consistency info:
	echo '
	.text
hsc.EDigits.lhs.40.0..:' >> /tmp/ghc25291.s

real        0.0
user        0.0
sys         0.0
*** New hi file follows...
_interface_ Main 400
_instance_modules_
IO PrelAddr PrelArr PrelBounded PrelCCall PrelForeign PrelIOBase PrelNum PrelNumExtra PrelTup

_usages_
IO 1 :: putChar 1;
Monad 1 :: sequence 1;
PrelBase 1 :: $dEnum0 1 $dEnumBool0 1 $dEnumChar0 1 $dEnumInt0 1 $dEnumOrdering0 1 $dEq0 1 $dEq1 1 $dEqBool0 1 $dEqChar0 1 $dEqInt0 1 $dEqInteger0 1 $dEqOrdering0 1 $dMonad0 1 $dMonadPlus0 1 $dMonadZero0 1 $dNumInt0 1 $dOrd0 1 $dOrd1 1 $dOrdBool0 1 $dOrdChar0 1 $dOrdInt0 1 $dOrdOrdering0 1 $dShow0 1 $dShow1 1 $dShow2 1 $dShowBool0 1 $dShowChar0 1 $dShowInt0 1 $dShowOrdering0 1 $m- 1 $m/= 1 $m< 1 $m<= 1 $m> 1 $m>= 1 $m>> 1 $mcompare 1 $menumFromThenTo 1 $menumFromTo 1 $mfromInt 1 $mmax 1 $mmin 1 $mshowList 1 addr2Integer 1 foldr 1 int2Integer 1 integer_0 1 integer_1 1 integer_2 1 integer_m1 1 otherwise 1 Enum 1 Eq 1 Monad 1 MonadPlus 1 MonadZero 1 Num 1 Ord 1 Ordering 1 Show 1 String 1;
PrelIOBase 1 :: $dMonadIO0 1 IO 1;
PrelList 1 :: repeat 1;
PrelNum 1 :: $dEnumInteger0 1 $dEqRatio0 1 $dIntegralInt0 1 $dIntegralInteger0 1 $dNumInteger0 1 $dOrdInteger0 1 $dRealInt0 1 $dRealInteger0 1 $dShowInteger0 1 $mdiv 1 $mdivMod 1 $mmod 1 $mquot 1 $mrem 1 Integral 1 Ratio 1 Rational 1 Real 1;
PrelNumExtra 1 :: $dEnumDouble0 1 $dEnumRatio0 1 $dEqDouble0 1 $dNumDouble0 1 $dNumRatio0 1 $dOrdDouble0 1 $dOrdRatio0 1 $dRealDouble0 1 $dRealRatio0 1 $dShowDouble0 1 $dShowRatio0 1;
PrelPack 1 :: packCString# 1 unpackAppendCString# 1 unpackCString# 1 unpackFoldrCString# 1 unpackNBytes# 1;
PrelTup 1 :: $dEq0 1 $dOrd0 1 $dShow3 1;
_exports_
Main convert edigits main mkdigit norm;
_declarations_
main _:_ PrelIOBase.IO PrelBase.() ;;
edigits _:_ [PrelBase.Char] ;;
convert _:_ [PrelBase.Int] -> [PrelBase.Char] ;;
mkdigit _:_ PrelBase.Int -> PrelBase.Char ;;
norm _:_ _forall_ [$a] {PrelNum.Integral $a, PrelBase.Num $a, PrelBase.Ord $a} => $a -> [$a] -> ($a, [$a]) ;;


ghc: module version changed to 1; reason: no old .hi file

Replace .hi file, if changed:
	cmp -s Main.hi /tmp/ghc25291.hi-new || ( rm -f Main.hi && cp /tmp/ghc25291.hi-new Main.hi )

real        0.0
user        0.0
sys         0.0

Unix assembler:
	gcc -o EDigits.o -c  -I. -I/home/III/a/ralf/FP/ghc/lib/includes -I/home/III/a/ralf/FP/ghc/lib/includes /tmp/ghc25291.s

real        0.2
user        0.1
sys         0.0

Linker:
	gcc -v -u PrelBase_IZh_static_info -u PrelBase_CZh_static_info -u PrelBase_False_static_closure -u PrelBase_True_static_closure -u PrelMain_mainIO_closure  EDigits.o  -L/home/III/a/ralf/FP/ghc/lib  -lHS -lHS_cbits -lHSrts -lgmp -lm
Reading specs from /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/specs
gcc version 2.7.2.3
 /usr/ccs/bin/ld -V -Y P,/usr/ccs/lib:/usr/lib -Qy -u PrelBase_IZh_static_info -u PrelBase_CZh_static_info -u PrelBase_False_static_closure -u PrelBase_True_static_closure -u PrelMain_mainIO_closure /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/crt1.o /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/crti.o /usr/ccs/lib/values-Xa.o /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/crtbegin.o -L/home/III/a/ralf/FP/ghc/lib -L/usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/gnu/gcc-2.7.2.3/lib EDigits.o -lHS -lHS_cbits -lHSrts -lgmp -lm -lgcc -lc -lgcc /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/crtend.o /usr/local/gnu/gcc-2.7.2.3/lib/gcc-lib/sparc-sun-solaris2.6/2.7.2.3/crtn.o
ld: Software Generation Utilities - Solaris/ELF (3.0)

real       11.9
user        0.9
sys         0.3
Checking consistency of: a.out

rm -f /tmp/ghc25291*
jod 78> a.out
a.out: fatal error: relocate_TSO
jod 79> 


BTW Hello world was successful.

Cheers, Ralf
----------
X-Sun-Data-Type: default
X-Sun-Data-Name: EDigits.lhs
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 71

-- NOTE: This script traces back to an example by David Turner supplied
-- with the Miranda system. Davis Turner's comments have been literally
-- copied.

Programming example - generating the digits of `e'

We wish to write a program to generate the (decimal) digits of  `e',  as
an  infinite  string.   Fact  -  the  value  of `e', the base of natural
logarithms, is given by the series

e = 1 + 1/1! + 1/2! + 1/3! + ...

where by n! we mean the factorial of n, = n*(n-1)...*2*1.  Now,  we  can
choose  to represent fractional numbers using a peculiar base system, in
which the weight of the i'th digit after the point is 1/i! (so note that
the  `carry factor' by which we must multiply a unit from the i'th digit
when carrying it back to the i-1'th is i).  Written to this funny  base,
`e' is just
        2.1111111111............
so  the  string we require may be obtained by converting fractional part
of the above numeral from the `funny base' to decimal.  Thus

> edigits		=  "2." ++ convert (repeat 1)

The function `convert' takes for its argument a fraction  in  the  funny
base  (here  represented as an infinite list of numbers) and returns its
value in decimal, as an infinite list  of  digits.   The  algorithm  for
converting  a  fraction from another base to decimal, is as follows: (i)
multiply all digits by ten, and renormalise, using the appropriate carry
factors (ii) the whole number part of the result gives the first decimal
digit (iii) repeat the process on the fractional part of the  result  to
generate the remaining digits.  Thus

> convert		:: [Int] -> [Char]
> convert x		=  mkdigit e' : convert x'
>     where (e',x')	=  norm 2 (0 : [ 10*a | a<-x ])
>
> mkdigit		:: Int -> Char
> mkdigit n		=  toEnum (n + fromEnum '0')

It remains to define the function `norm' which does renormalisation.  A 
naive (and almost correct) definition is

   norm c (d:x)		=  (d + e' `div` c, e' `mod` c : x')
       where (e',x')	=  norm (c+1) x

However, this is not a well-founded  recursion,  since  it  must  search
arbitrarily  far  to  the  right in the fraction being normalised before
printing the first digit.  If you try printing `edigits' with the  above
as  your  definition  of  norm,  you  will  get  "2." followed by a long
silence.

We need a theorem which will limit the distance from which a  carry  can
propogate.   Fact:  during  the  conversion of this fraction the maximum
possible carry from a digit to its leftward neighbour is 9.  (The  proof
of  this,  left  as  a  (not  very hard) exercise for the mathematically
minded reader, is by induction on the number  of  times  the  conversion
algorithm  is  applied.)  This  leads  us to the following slightly more
cautious definition of `norm'

> norm c (d:e:x)
>   | e `mod` c + 9 < c	=  (d + e  `div` c, e' `mod` c : x')
>   | otherwise		=  (d + e' `div` c, e' `mod` c : x')
>   where (e',x')	=  norm (c+1) (e:x)

Our solution is now complete.  To see the results, enter Hugs with  this
file as the current script and say
        edigits
Hit  control-C (interrupt) when you have seen enough digits.

> main			=  sequence [ putChar c | c<-edigits ]

Reply via email to