Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Module for making english lists?

by Fletch (Bishop)
on Aug 26, 2008 at 00:25 UTC ( [id://706807]=note: print w/replies, xml ) Need Help??


in reply to Module for making english lists?

Probably not the module you're looking for, but then again you're not going to be able to turn any of the others in for your homework either . . .

module Main where eng_commafy :: (Show a) => [a] -> String eng_commafy x | length x > 2 = foldl1 (commacat) init_as_show ++ ", a +nd " ++ last_show where commacat x y = x ++ ", " ++ y init_as_show = map (show) (init x) last_show = show (last x) eng_commafy x | length x == 2 = (show (head x)) ++ " and " ++ (show (l +ast x)) eng_commafy x | length x == 1 = show (head x) eng_commafy [] = "" main = do putStrLn (eng_commafy [1..10]) putStrLn (eng_commafy [1,2]) putStrLn (eng_commafy [1])

(Yeah, my Haskell's terrible . . . :)

Update: Actually looking at the OP's posting history this is probably not homework. But it's still trivial and probably not past the threshold of "should be stuck in a module" on its own.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://706807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found