[Haskell-cafe] How to solve this problem?It's quite easy in PHP.

Henk-Jan van Tuyl hjgtuyl at chello.nl
Fri Feb 16 16:35:07 EST 2007


On Thu, 15 Feb 2007 23:17:11 +0100, Gene A <yumagene at gmail.com> wrote:

> 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



More information about the Haskell-Cafe mailing list