How to solve this problem?It's quite easy in PHP.

For example, ----------------------------------- <?php //test.php require ("tiny.php");//Tiny is a small template engine. $tn=new Tiny(); $arr=new Array(); $arr['a']='1'; $arr['b']='2'; $arr['c']='3'; $tn->set('arr',$arr); $tn->show('_test.php'); ?> ----------------------------------- <?php require('_header.php');?> <?php foreach($arr as $key => $val){ echo "$key = $val <br>"; } ?> <?php require('_footer.php');?> ----------------------------------- a = 1 b = 2 c = 3 -----------------------------------

keepbal:
For example, ----------------------------------- <?php //test.php require ("tiny.php");//Tiny is a small template engine. $tn=new Tiny(); $arr=new Array(); $arr['a']='1'; $arr['b']='2'; $arr['c']='3'; $tn->set('arr',$arr); $tn->show('_test.php'); ?> ----------------------------------- <?php require('_header.php');?> <?php foreach($arr as $key => $val){ echo "$key = $val <br>"; } ?> <?php require('_footer.php');?> ----------------------------------- a = 1 b = 2 c = 3 -----------------------------------
Doesn't look that easy. I guess its not too bad though. Anyway, here's Data.Map for you: import Data.Map import Text.Printf m = fromList (zip "abc" [1..]) main = mapM_ draw (toList m) draw (k,v) = printf "%c = %d\n" k (v :: Int) And if you want to run this: $ runhaskell A.hs a = 1 b = 2 c = 3

Hi Eeek, a solution that does monadic maps and require's rank 2 types! arr = [('a',1), ('b',2), ('c',3)] showAll = lines (map showItem arr) showItem (a,n) = a : " = " ++ show n main = putStr showAll I've broken this up a bit more than usual - most people would probably just put showAll inside main, but this separates out the concepts. arr is the data, which you could construct with a zip if that really is all there is to it. showItem shows a single item, showAll shows them all, and main just prints out the information. And this solution is Haskell 98, anything that uses printf is Haskell' only. Thanks Neil

ndmitchell:
Hi
Eeek, a solution that does monadic maps and require's rank 2 types!
arr = [('a',1), ('b',2), ('c',3)] showAll = lines (map showItem arr) showItem (a,n) = a : " = " ++ show n main = putStr showAll
I've broken this up a bit more than usual - most people would probably just put showAll inside main, but this separates out the concepts. arr is the data, which you could construct with a zip if that really is all there is to it. showItem shows a single item, showAll shows them all, and main just prints out the information.
And this solution is Haskell 98, anything that uses printf is Haskell' only.
Thanks
Neil
$ hugs +98 __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: March 2005 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Hugs.Base> :l Text.Printf Text.Printf> printf "%d" (1::Int) :: String "1" Fix YHC! :-) -- Don

Hi Don,
Type :? for help Hugs.Base> :l Text.Printf Text.Printf> printf "%d" (1::Int) :: String "1"
My bad - sorry, too many presentations/papers were people encoded printf using multi-ranked-generalised-associated types :)
Fix Yhc!
Fair point, should be as simple as compiling that file... Thanks Neil

Using printf doesn't need Haskell'. I wrote to require only Haskell98. -- Lennart On Feb 14, 2007, at 11:36 , Neil Mitchell wrote:
Hi
Eeek, a solution that does monadic maps and require's rank 2 types!
arr = [('a',1), ('b',2), ('c',3)] showAll = lines (map showItem arr) showItem (a,n) = a : " = " ++ show n main = putStr showAll
I've broken this up a bit more than usual - most people would probably just put showAll inside main, but this separates out the concepts. arr is the data, which you could construct with a zip if that really is all there is to it. showItem shows a single item, showAll shows them all, and main just prints out the information.
And this solution is Haskell 98, anything that uses printf is Haskell' only.
Thanks
Neil _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 2/13/07, keepbal
For example, (... $arr['a']='1'; $arr['b']='2'; $arr['c']='3'; ...) result:
a = 1 b = 2 c = 3
Haskell solution: build the array of all lower case with corresponding numbers starting with 1 Prelude> let lowerCaseTable = zip ['a'..'z'] [1..26] A couple of functions: Prelude> let box a = a:[] Prelude> let formatTableItems (a,b) = (box a) ++ " = " ++ (show b) ++ "\n" Then to output the results: putStrLn $ foldr (++) "\n"$ map formatTableItems lowerCaseTable a = 1 b = 2 c = 3 d = 4 e = 5 f = 6 g = 7 h = 8 i = 9 j = 10 k = 11 l = 12 m = 13 n = 14 o = 15 p = 16 q = 17 r = 18 s = 19 t = 20 u = 21 v = 22 w = 23 x = 24 y = 25 z = 26 I think that is pretty simple... Good cheer to all from the desert, gene

On 2/15/07, Gene A
Haskell solution: build the array of all lower case with corresponding numbers starting with 1
Prelude> let lowerCaseTable = zip ['a'..'z'] [1..26]
A couple of functions: Prelude> let box a = a:[] Prelude> let formatTableItems (a,b) = (box a) ++ " = " ++ (show b) ++ "\n"
Then to output the results: putStrLn $ foldr (++) "\n"$ map formatTableItems lowerCaseTable a = 1 b = 2
That last output function group could have been simpler.. I sometimes forget concatMap.. as I did there it should have been: Prelude> putStrLn $ concatMap formatTableItems lowerCaseTable a = 1 b = 2 c = 3 etc.... even simpler than the first.. where I used map and then foldr cheers, gene

On Thu, 15 Feb 2007 23:17:11 +0100, Gene A
A couple of functions: Prelude> let box a = a:[] Prelude> let formatTableItems (a,b) = (box a) ++ " = " ++ (show b) ++ "\n"
This can be done simpler:
formatTableItems (a,b) = [a] ++ " = " ++ (show b) ++ "\n"
Yet simpler:
formatTableItems (a,b) = a : " = " ++ (show b) ++ "\n"
To improve further:
formatTableItems (a,b) = a : " = " ++ (show b) ++ "\n" putStrLn $ foldr (++) "\n"$ map formatTableItems lowerCaseTable can be replaced with: formatTableItems (a,b) = a : " = " ++ (show b) putStrLn $ unlines $ map formatTableItems lowerCaseTable
-- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433
participants (6)
-
dons@cse.unsw.edu.au
-
Gene A
-
Henk-Jan van Tuyl
-
keepbal
-
Lennart Augustsson
-
Neil Mitchell