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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:11:54+00:00 2026-06-02T22:11:54+00:00

I have been given with the language semantics and everything i should know.It’d only

  • 0

I have been given with the language semantics and everything i should know.It’d only support few operations and there wouldn’t be any concept of Data Types. So i can store anything in a variable and operate on them.

I’d have loops and conditions and function calls and that is it.
I am looking for a start, an example not a theory book. Has anyone ever implemented such a basic language interpreter in Haskell? I am looking for pointers and references.

Thanks !

  • 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-02T22:11:55+00:00Added an answer on June 2, 2026 at 10:11 pm

    I’m working on one right now as a practice project.

    It’s a dynamically-typed language, so variables don’t have to be declared, but each value has an associated type. I implemented that using an algebraic data type in Haskell:

    data Value = BoolValue Bool  -- ^ A Boolean value.
               | NumberValue Double  -- ^ A numeric value.
               | StringValue String  -- ^ A string value.
               -- (several others omitted for simplicity)
    

    For execution of programs, I’m using the StateT and ErrorT monad transformers on top of IO:

    -- | A monad representing a step in an RPL program.
    --
    -- This type is an instance of 'MonadState', so each action is a function that
    -- takes an 'RPLContext' as input and produces a (potentially different)
    -- 'RPLContext' as its result.  It is also an instance of 'MonadError', so an
    -- action may fail (with 'throwRPLError').  And it is built on the 'IO' monad,
    -- so 'RPL' computations can interact with the outside world.
    type RPL = StateT RPLContext (ErrorT RPLError IO)
    
    -- | Executes an 'RPL' computation.
    -- The monadic result value (of type @a@) is discarded, leaving only the final
    -- 'RPLContext'.
    runRPL :: RPL a  -- ^ The computation to run
           -> RPLContext  -- ^ The computation's initial context
           -> IO (Either RPLError RPLContext)
           -- ^ An 'IO' action that performs the operation, producing either
           -- a modified context if it succeeds, or an error if it fails.
    runRPL a = runErrorT . (execStateT a)
    

    The “context” is a combination of a data stack (it’s a stack-based language) and an “environment” that holds all the variables that are currently in scope:

    -- | The monadic state held by an 'RPL' computation.
    data RPLContext = RPLContext {
      contextStack :: Stack,  -- ^ The context's data stack.
      contextEnv :: Env  -- ^ The context's environment.
    }
    

    (Note that Stack is just an alias for [Value].)

    On top of that foundation, I have a variety of helper functions to do things like manipulate the stack in the current context (held by the StateT part of the RPL monad). For example, here are the functions involved in pushing a value onto the stack:

    -- | Pushes a value onto the stack.
    pushValue :: Value -> RPL ()
    pushValue x = modifyStack (x:)
    
    -- | Transforms the current stack by a function.
    modifyStack :: (Stack -> Stack) -> RPL ()
    modifyStack f = do
      stack <- getStack
      putStack $ f stack
    
    -- | Returns the entire current stack.
    getStack :: RPL Stack
    getStack = fmap contextStack get
    
    -- | Replaces the entire current stack with a new one.
    putStack :: Stack -> RPL ()
    putStack stack = do
      context <- get
      put $ context { contextStack = stack }
    

    getStack, putStack, and modifyStack are modeled after MonadState‘s get, put, and modify functions, but they operate on just one field of the RPLContext record.

    All the language’s built-in commands are just actions in the RPL monad, which build on top of tools like pushValue.

    For parsing code in my language, I’m using Parsec. It’s pretty nice.


    On a separate track, unrelated to my RPL interpreter, you might find “Write Yourself a Scheme in 48 Hours” helpful.

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

Sidebar

Related Questions

I have worked in C language, but now i have been given this work
I have been given the following request. Please give 7% of the current contacts
I have been given the option to either have a Windows laptop or a
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the unenviable task of cleaning up after a developer who
I have been given an app written by someone else and the error I
I have been given a WSDL file and I need to consume a web
I have been given the task to design a database to store a lot
I have been given a staff list which is supposed to be up to
i have been given class with int variables x and y in private, and

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.