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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:20+00:00 2026-05-28T08:26:20+00:00

I’m trying to make a simple Scheme interpreter in Haskell. As part of this,

  • 0

I’m trying to make a simple Scheme interpreter in Haskell. As part of this, I’m implementing some primitive operators like number?, string? etc.

I have code like this:

isNumber :: [LispVal] -> LispVal
isNumber ([Number n]) = Bool True
isNumber            _ = Bool False

isString :: [LispVal] -> LispVal
isString ([String n]) = Bool True
isString            _ = Bool False

And what I’d like is something like

isType :: ?? -> [LispVal] -> LispVal
isType (typeName [typeName n]) = Bool True
isType                       _ = Bool False

In other words, I’d like to create the equivalent of isNumber by saying “isType Number”. Is this possible somehow? I’m struggling to find anything similar in Google, maybe because I don’t know what to call the situation.

  • 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-28T08:26:20+00:00Added an answer on May 28, 2026 at 8:26 am

    I’m assuming you have a type something like this:

    data LispVal = String String | Number Double -- &c....
    

    …and you want a function that tests whether a LispVal value is a particular constructor (String, Number, &c.) based on some argument.

    There’s not really a straightforward, generic way to do this, unfortunately.

    You could resort to string comparisons:

    getTypeName :: LispVal -> String
    getTypeName (String _) = "String"
    getTypeName (Number _) = "Number"
    
    isType :: String -> [LispVal] -> LispVal
    isType name [val] = Bool (name == getTypeName val)
    isType _ _ = Bool False
    

    Or you could compare the types of two LispVals:

    sameType :: LispVal -> LispVal -> LispVal
    sameType (String _) (String _) = Bool True
    sameType (Number _) (Number _) = Bool True
    sameType _ _ = Bool False
    

    …and then create a dummy value to compare with for isType.

    You could also make a “type” value and implement a sort of reflection on LispVals, then compare based on those:

    data LispType = LispString | LispNumber | LispType
    
    getType :: LispVal -> LispVal
    getType (String _) = Type LispString
    getType (Number _) = Type LispNumber
    getType (Type _) = Type LispType
    
    isType :: LispVal -> [LispVal] -> LsipVal
    isType t [v] = isEqual t (getType v)
    isType _ _ = Bool False
    

    Some variation on one of these approaches is probably your best option. There are other ways, based on more advanced features of Haskell, but they’re probably not worth the hassle unless the interpreted language’s types tie much more closely to Haskell’s types.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,

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.