Skip to content

Instantly share code, notes, and snippets.

@nobleach nobleach/
Created Feb 12, 2018

What would you like to do?
Bottles of Beer
let bottles = function
| 0 -> "no more bottles"
| 1 -> "1 bottle"
| n -> Printf.sprintf "%d bottles" n;;
let rec sing n =
let current = bottles n in
let next = bottles (n-1) in
"%s of beer on the wall, %s of beer.\n"
(String.capitalize_ascii current) current ;
if n > 0 then begin
"Take one down and pass it around, %s of beer on the wall.\n\n"
next ;
sing (n-1)
end else
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
let run = sing 99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.