Dynamic variables ...

Amr Sabry sabry@cs.indiana.edu
Thu, 23 May 2002 09:51:20 -0500


Using Hugs -98 (Dec. 2001), the following diverges during typechecking:

runList :: (?basis_elem :: [a]) => Int -> ((?basis :: [[a]]) => t) -> t
runList n x = x with ?basis = allLists n ?basis_elem

Using one pair for (n,x) gives something like John Hughes bug 10 on
http://cvs.haskell.org/Hugs/pages/buglist.html. The variants below all
work fine. --Amr

---------------------------------------------

runPair :: (?basis_a :: [a], ?basis_b :: [b]) => ((?basis :: [(a,b)]) => t) -> t
runPair x = x with ?basis = [(a,b) | a <- ?basis_a, b <- ?basis_b ]

runTriple :: (?basis_a :: [a], ?basis_b :: [b], ?basis_c :: [c]) => 
             ((?basis :: [(a,b,c)]) => t) -> t
runTriple x = x with 
              ?basis = [(a,b,c) | a <- ?basis_a, b <- ?basis_b, c <- ?basis_c ]

runList3 :: (?basis_elem :: [a]) => ((?basis :: [[a]]) => t) -> t
runList3 x = x with ?basis = allLists 3 ?basis_elem

allLists :: Int -> [a] -> [[a]]
allLists 0 _ = [[]]
allLists n bs = [ x:xs | x <- bs, xs <- allLists (n-1) bs ]