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 8627059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:10:59+00:00 2026-06-12T08:10:59+00:00

I want to ask the user to input a variable and check it is

  • 0

I want to ask the user to input a variable and check it is real or integer and take two different operations for corresponding actions. Say true if integer else false;

fun realorinteger(n)= if n=int then true else false;

but it definitely does not work. I tried if n in int as well.

Any help?

  • 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-06-12T08:11:00+00:00Added an answer on June 12, 2026 at 8:11 am

    You cannot do this.

    The type system simply doesn’t allow a function to take multiple different types, and act according to which type it is. Either your function takes an int, or it takes a real. (Or it takes both, but can also take strings, lists, etc… ie. is polymorphic)

    You could fake it by making a datatype, which encapsulates values that can be either integers or reals, like so:

    datatype intorreal = IVal of int | RVal of real
    

    You can then use pattern matching on such a value to extract the desired number:

    fun realorinteger (IVal i) = ... (* integer case here *)
      | realorinteger (RVal r) = ... (* real case here *)
    

    This function will then have the type intorreal -> x, where x is the type of the right-hand-side expressions. Note, the resulting value must be of the same type in both cases.

    An example of such a function could be a rounding function:

    fun round (IVal i) = i
      | round (RVal r) = Real.round r
    

    Which is then called like so:

    val roundedInt  = round (IVal 6);
    val roundedReal = round (RVal 87.2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to ask user to input something but not want to wait forever. There
I want to ask the user for input in console. He'll be writing down
I want to ask the user to input a password. As the password is
I am working on a program that take user input for two file names.
Alright so in Java I want to ask the user for a time in
In my GWT application, I want to ask a user confirmation when he navigates
Suppose I ask the user do you want to run in 32bit mode or
I want to have a menu display that accepts user input. However, I want
In my lua program, i want to stop and ask user for confirmation before
What I want to do is ask the user for a number of strings

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.