I am just starting to delve into some programs and decided to go with F #. As a practice, I tried to convert the script I made in .bat to F #. I had a problem creating a looping function that does more than one. Here is the code from the old script for this loop.
:Select
cls
echo.
echo Which Game?
echo.
echo 1. Assassin Creed
echo 2. Crysis
echo 3. Mass Effect
echo.
echo.
set/p "game=>"
if /I %game%==1 goto Creed
if /I %game%==2 goto Crysis
if /I %game%==3 goto Mass
echo.
echo Invalid selection!
echo.
echo.
pause
goto Select
The code I tried to do for the same function in F # looks like this:
let rec gameprint gameselect =
printfn "Which Game?\n\n 1.%s\n 2.%s\n 3.%s\n\n\n" game1 game2 game3
let mutable gameselect = Int32.Parse(stdin.ReadLine())
if gameselect = "1" then game1
elif gameselect = "2" then game2
elif gameselect = "3" then game3
else printf "temp"
Console.Clear
I know that I am missing something that says it starts up again if it reaches the last "else"; and I get these errors:
The expression must be of type 'unit', but of type 'string'. Use "ignore" to cancel the result of the expression, or "let" bind the result to the name.
1 int, 19 21
2 int, 20 23
3 int, 21 23
4 , , 22 17
5 'unit', 'string'. "", , "" . 19 5
( ):
let rec getGame() =
match Int32.Parse(stdin.ReadLine()) with
| 1 -> "Assassin Creed"
| 2 -> "Crysis"
| 3 -> "Mass Effect"
| _ -> printf "Temp"
:
1 , , 36 19
, , "printf" "Console.Clear"
, , , , : -)
!