Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1080861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:05:36+00:00 2026-05-16T22:05:36+00:00

I’m just starting to dig into some programming and decided to go with F#.

  • 0

I’m just starting to dig into some programming and decided to go with F#. As practice, I was trying to convert a script I made in .bat into F#. I’m having trouble creating a looping function that does more than one thing. Here is the code from the old script for this loop.

:Select
cls
echo.
echo Which Game?
echo.
echo    1. Assassin's 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’ve tried to make for the same function in F# looks like this so far:

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 I’m missing something that tells it to run again if it reaches the last “else”; and I’m getting these errors:

The expression should have type ‘unit’ but has type ‘string’. Use ‘ignore’ to discard the result of the expression, or ‘let’ to bind the result to a name.

Error 1 This expression was expected to have type int but here has type string 19 21

Error 2 This expression was expected to have type int but here has type string 20 23

Error 3 This expression was expected to have type int but here has type string 21 23

Error 4 This expression was expected to have type string but here has type unit 22 17

Warning 5 This expression should have type ‘unit’, but has type ‘string’. Use ‘ignore’ to discard the result of the expression, or ‘let’ to bind the result to a name. 19 5

I’d prefer to use an approach like this (Very incomplete):

let rec getGame() =
    match Int32.Parse(stdin.ReadLine()) with
    | 1 -> "Assassin's Creed"
    | 2 -> "Crysis"
    | 3 -> "Mass Effect"
    | _ -> printf "Temp"

But I’m getting:

Error 1 This expression was expected to have type string but here has type unit 36 19

And I’m not sure how I would loop it and make it ‘printf’ and ‘Console.Clear’

If there is a more functional approach that I don’t know about, I would certainly love to learn 🙂

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:05:36+00:00Added an answer on May 16, 2026 at 10:05 pm

    The biggest problem with your first attempt is that you’re parsing the input from a string into an int, but then you try to pattern match against strings. Using 1, 2, and 3 instead of "1", "2", and "3" will fix that problem, but then you’ll be at roughly the same point as your second attempt.

    Your second attempt nearly works, but F# is telling you that you aren’t using a consistent return type across all of your branches: in the first three cases you’re returning a string but in the last case you’re not returning anything. All you need to do is loop in that case, and the compiler will be happy:

    let rec getGame() =
        match Int32.Parse(stdin.ReadLine()) with
        | 1 -> "Assassin's Creed"
        | 2 -> "Crysis"
        | 3 -> "Mass Effect"
        | _ -> printf "Temp"; getGame()
    

    I’d do something more like this:

    type Game = Creed | Crysis | Mass
    
    let rec getGame() =
      printfn "Which Game?\n\n   1.%A\n   2.%A\n   3.%A\n\n" Creed Crysis Mass
      match stdin.ReadLine() |> Int32.TryParse with
      | true,1 -> Creed
      | true,2 -> Crysis
      | true,3 -> Mass
      | _ -> 
         printfn "You did not enter a valid choice."
         // put any other actions you want into here
         getGame()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a JSP page retrieving data and when single or double quotes are
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.