Difference between revisions of "Unix tools/yes"

From HaskellWiki
Jump to navigation Jump to search
m
m (Various minor changes)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
== yes ==
 
== yes ==
   
A simple utility to repeatedly print y to standard out.
+
A simple utility to repeatedly print <code>"y"</code> to standard output.
   
Here are some various ways this simple program can be written.
+
Here are some various ways this small program can be written:
   
  +
{|
<haskell>
+
|<haskell>
main = let y = putStrLn "y" >> y in y
+
main = let y = putStrLn "y" >> y in y
 
</haskell>
 
</haskell>
  +
|}
   
  +
{|
<haskell>
+
|<haskell>
main = putStrLn $ concat $ repeat "y\n"
+
main = putStrLn $ concat $ repeat "y\n"
 
</haskell>
 
</haskell>
  +
|}
  +
  +
{|
  +
|<haskell>
  +
main = let y = 'y' : '\n' : y in putStrLn y
  +
</haskell>
  +
|}
  +
  +
{|
  +
|<haskell>
  +
main = putStrLn "y" >> main
  +
</haskell>
  +
|}
  +
  +
{|
  +
|<haskell>
  +
main = putStrLn $ cycle "y\n"
  +
</haskell>
  +
|}

Latest revision as of 03:24, 26 April 2021

yes

A simple utility to repeatedly print "y" to standard output.

Here are some various ways this small program can be written:

main = let y = putStrLn "y" >> y in y
main = putStrLn $ concat $ repeat "y\n"
main = let y = 'y' : '\n' : y in putStrLn y
main = putStrLn "y" >> main
main = putStrLn $ cycle "y\n"