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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:22:58+00:00 2026-05-28T04:22:58+00:00

How can I find the type of a value in Haskell? I want something

  • 0

How can I find the type of a value in Haskell?

I want something like this:

data Vegetable = 
  Und Under
 |Abv Above

is_vegetable ::a->Bool  
is_vegetable a = if (a is of type Vegetable) then True else False

Update:

I want a datastructure to model the above tree.

I would also like to have some functions (is_drink, is_vegetable,is_wine,is_above) so that I can apply some filters on a list.
enter image description here

  • 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-28T04:22:59+00:00Added an answer on May 28, 2026 at 4:22 am

    You cannot do this in Haskell. All function arguments have concrete types (like Int and String) or they are type variables (like the a in your example). Type variables can be restricted to belong to a certain type class.

    When you use an unrestricted type variable, then you cannot do anything interesting with the values of that type. By restricting the type variable to a type class, you get more power: if you have Num a, then you know that a is a numeric type and so you can add, multiple, etc.

    From your comment, it sounds like you need a (bigger) data type to hold the different types of elements in your tree. The Either a b type may come in handy here. It is either Left a or Right b and so you can have a function like

    is_vegetable :: Either Vegetable Drink -> Bool
    is_vegetable (Left _) = True
    is_vegetable (Right _) = False
    

    Your tree nodes will then be Either Vegetable Dring elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it's simple. I can't find it any where. I want something like:
Is string a value type or a reference type? I just can't find a
How can I find out the type of a NSDictionary element?
How can we find the system type (i.e. 32-bit or 64-bit) using Python...?
Where can I find an overview of type conversion, e.g. string to integer, etc.?
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can
I can find the tool command in my filesystem under: /Applications/Xcode.app/Contents/Developer/usr/bin/otool If I specify
I can find the definition files at http://www.php.net/~helly/php/ext/spl/... but I want to extend DirectoryIterator
Typical Event Log message looks like below. There you can find very interesting fields
I can't find the type of problem I have and I was wondering if

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.