Dear hugs-bugs,
I am not sure if "INTERNAL ERROR: Bignum expected" indicates an
error in hugs, but here is a program that produces one, with the version
of November 1999.
Regards,
Peter Hancock
Linux premise 2.2.13 #9 Sat Nov 27 14:35:55 GMT 1999 i586 unknown
redhat 6.1, mainly.
program
----------
> import List
> data Expr = Leaf Char | Fork Char Expr Expr deriving Eq
Returns textual representation of a buffer.
> type Buffer = String -> String
> showExpr :: Expr -> Buffer
> showExpr e =
> f '-' e
> where f b (Leaf n) = (n:)
> f b (Fork c t1 t2) = if b `lt` c then p else ('(':) . p . (')' :)
> where p = f c t1
> . (' ':)
> . (c:)
> . (' ':)
> . f c t2
> lt '/' c = False
> lt '*' c = c `elem` "/"
> lt '+' c = c `elem` "/*"
> lt '-' c = c `elem` "/*+"
> instance Show Expr where
> showsPrec n e = showExpr e
> trees ns = [ Leaf n | n <- ns ] ++ trees' ns
> trees' ns = [ Fork c t1 t2 | c <- ['+','*','-','/']
> , ms <- propersubsets ns
> , t1 <- trees ms
> , t2 <- trees (ns \\ ms) ]
> eval (Leaf n) = toRational (fromInt (fromEnum n - fromEnum '0'))
> eval (Fork '+' t1 t2) = eval t1 + eval t2
> eval (Fork '*' t1 t2) = eval t1 * eval t2
> eval (Fork '-' t1 t2) = eval t1 - eval t2
> eval (Fork '/' t1 t2) = let x2 = eval t2 in
> if x2 /= 0 then eval t1 / x2 else 0
> main = let d = heading . body
> heading = ("Args\tNumbers"++)
> body = cl [ entry t | t <- prefixes "123456" ]
> entry str = let nos = numbers str
> n = length nos
> in ("\n"++) . (str++)
> . ("\t"++) . shows n
> . ("\t"++) . shows nos
> numbers = sort . nub . map eval . trees
> emit :: Buffer -> String
> emit f = f ""
> in putStr (emit d)
Return a list in increasing order of the (proper) initial segments of a list.
> prefixes, properprefixes :: [a] -> [[a]]
> prefixes xs = [] : properprefixes xs
> properprefixes (x:xs) = [ x : p | p <- prefixes xs ]
Return a list of (proper) sublists of a lits.
> subsets, propersubsets :: [a] -> [[a]]
> subsets xs = xs : propersubsets xs
> propersubsets (x:xs) = [ x:s | s <- propersubsets xs ] ++ subsets xs
> propersubsets [] = []
compose a finite list of functions.
> cl :: [a -> a] -> a -> a
> cl = foldr (.) id
Main> main
Args Numbers
0 []
1 1 [1 % 1]
12 5 [-1 % 1,1 % 2,1 % 1,2 % 1,3 % 1]
123 29 [-5 % 1,-4 % 1,-3 % 1,-5 % 2,-2 % 1,-5 % 3,-1 % 1,-1 % 2,-1 % 3,0 %
1,1 % 6,1 % 5,1 % 3,1 % 2,2 % 3,1 % 1,3 % 2,5 % 3,2 % 1,7 % 3,5 % 2,3 % 1,7 % 2,4 %
1,5 % 1,6 % 1,7 % 1,8 % 1,9 % 1]
1234 230 [-23 % 1,-22 % 1,-21 % 1,-20 % 1,-19 % 1,-18 % 1,-17 % 1,-16 % 1,-15 %
1,-14 % 1,-13 % 1,-12 % 1,-23 % 2,-11 % 1,-21 % 2,-10 % 1,-9 % 1,-8 % 1,-23 % 3,-22 %
3,-7 % 1,-20 % 3,-13 % 2,-6 % 1,-23 % 4,-17 % 3,-11 % 2,-21 % 4,-5 % 1,-19 % 4,-9 %
2,-13 % 3,-4 % 1,-23 % 6,-19 % 5,-11 % 3,-7 % 2,-10 % 3,-13 % 4,-3 % 1,-23 % 8,-17 %
6,-11 % 4,-13 % 5,-5 % 2,-12 % 5,-7 % 3,-9 % 4,-2 % 1,-23 % 12,-13 % 7,-11 % 6,-7 %
4,-12 % 7,-5 % 3,-8 % 5,-3 % 2,-7 % 5,-11 % 8,-4 % 3,-5 % 4,-7 % 6,-1 % 1,-6 % 7,-5 %
6,-4 % 5,-3 % 4,-8 % 11,-5 % 7,-2 % 3,-5 % 8,-3 % 5,-7 % 12,-6 % 11,-1 % 2,-3 % 7,-5 %
12,-2 % 5,-1 % 3,-3 % 10,-1 % 4,-2 % 9,-1 % 5,-2 % 11,-1 % 6,-1 % 7,-1 % 8,-1 % 10,-1
% 12,0 % 1,1 % 24,1 % 20,1 % 18,1 % 14,1 % 12,1 % 11,1 % 10,1 % 9,1 % 8,2 % 15,1 % 7,2
% 13,1 % 6,2 % 11,1 % 5,3 % 14,2 % 9,1 % 4,2 % 7,3 % 10,1 % 3,4 % 11,3 % 8,2 % 5,5 %
12,3 % 7,4 % 9,6 % 13,1 % 2,6 % 11,4 % 7,7 % 12,3 % 5,8 % 13,5 % 8,2 % 3,5 % 7,8 %
11,3 % 4,4 % 5,5 % 6,6 % 7,7 % 8,11 % 12,1 % 1,8 % 7,7 % 6,6 % 5,5 % 4,9 % 7,4 % 3,11
% 8,7 % 5,3 % 2,8 % 5,13 % 8,5 % 3,12 % 7,7 % 4,9 % 5,11 % 6,13 % 7,23 % 12,2 % 1,25 %
12,15 % 7,13 % 6,9 % 4,7 % 3,12 % 5,5 % 2,13 % 5,8 % 3,11 % 4,17 % 6,23 % 8,3 % 1,25 %
8,19 % 6,13 % 4,10 % 3,17 % 5,7 % 2,11 % 3,15 % 4,19 % 5,23 % 6,4 % 1,25 % 6,21 % 5,13
% 3,9 % 2,14 % 3,19 % 4,5 % 1,21 % 4,11 % 2,17 % 3,23 % 4,6 % 1,25 % 4,19 % 3,13 %
2,20 % 3,27 % 4,7 % 1,22 % 3,15 % 2,23 % 3,8 % 1,25 % 3,26 % 3,9 % 1,28 % 3,10 % 1,21
% 2,11 % 1,23 % 2,12 % 1,25 % 2,13 % 1,27 % 2,14 % 1,15 % 1,16 % 1,17 % 1,18 % 1,19 %
1,20 % 1,21 % 1,22 % 1,23 % 1,24 % 1,25 % 1,26 % 1,27 % 1,28 % 1,30 % 1,32 % 1,36 % 1]
12345
INTERNAL ERROR: Bignum expected
Main>