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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:59:52+00:00 2026-05-28T13:59:52+00:00

i have a question regarding this Haskell code: module Queue (Queue, emptyQueue, queueEmpty, enqueue,

  • 0

i have a question regarding this Haskell code:

module Queue (Queue, emptyQueue, queueEmpty, enqueue, dequeue, front) where

newtype Queue a = MakeQ([a])

emptyQueue :: Queue a
emptyQueue = MakeQ([])

queueEmpty :: Queue a -> Bool
queueEmpty (MakeQ(q)) = null q

enqueue :: a -> Queue a -> Queue a
enqueue x (MakeQ(q)) = MakeQ(q ++ [x])

dequeue :: Queue a -> Queue a
dequeue (MakeQ(x:q)) = MakeQ(q)

front :: Queue a -> a
front (MakeQ(x:q)) = x

I know how a queue generally works and what each of the operations mainly does. My first problem is that i don’t know how to use the operations in hugs. How do i create a empty queue or put an element in it after i created it? I tried several commands but all of them resulted in error messages, i.e. Make([]), emptyQueue [] … I know that those commands are very naive, but i am absolutly not familiar with Haskell and need it only for 2 weeks or so.

Second question is regarding the “MakeQ” itself. This is just a declaration for a name for our operation, correct? Or is it a static Haskell command? Imo it could be also “QQQ” or whatever. I can’t really test whether this would crash the programm or not because i don’t know how to use this module.

Even if my question seem kind of stupid, i would be really happy if someone could give me an explanation or hints…

  • 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-28T13:59:53+00:00Added an answer on May 28, 2026 at 1:59 pm

    emptyQueue by itself is an empty queue; you don’t have to pass any parameters to it.

    MakeQ is just an arbitrary name, you’re right; it could be anything (as long as you changed all the other uses of it). In this case, it’s the constructor for Queue: if xs is a list of a values (i.e. has type [a]), then MakeQ xs is a Queue a. However, the module does not export MakeQ, so you can’t use it from outside — it’s used as part of the implementation, and hidden to maintain an abstraction; it could easily be rewritten in terms of another, non-list structure without breaking any code that uses the module.

    Operations on the queue are done, not by updating an existing queue in-place, but by transforming a queue into new queues. For instance, if a is an Int, and q is a Queue Int, then enqueue a q is another Queue Int with a added to the back. Similarly, if q is a Queue Int, then dequeue q is another Queue Int without the front element, and front q is the front element itself (an Int).

    Also, note that Hugs is not maintained any more; you should consider installing the Haskell Platform, which is based on the GHC compiler. It contains an “interpreter” program just like Hugs, so it’s not just a standard compiler.

    Here’s an example of how this queue module could be used from an interactive prompt:

    GHCi> let q = emptyQueue :: Queue Int
    GHCi> let q1 = enqueue 42 q
    GHCi> front q1
    42
    GHCi> let q2 = enqueue 43 q1
    GHCi> front q2
    43
    GHCi> front (dequeue q2)
    42
    

    If you’re trying to maintain a queue throughout the execution of a program, then you probably want to use the state monad, which is a lot less scary than it sounds. 🙂 I would recommend reading Learn You a Haskell, which is an excellent Haskell tutorial covering, among many other things, the state monad.

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

Sidebar

Related Questions

I have a question regarding to the code that OCRApiService.com provides to devs. This
I have a question regarding this code. I'm a beginner and enjoy learning C#.
I have a question regarding this code: int main() { printf(%d,sizeof()); } It prints
I have a question regarding this code. I write this code in my framework,
I have a question regarding this article. Between this code function odds(n, p) {
i have a question regarding using Transaction. Consider this code: declare @trans_name varchar(max) =
So I'm reading K&R book and I have a question regarding this code: int
Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
I have this very straight forward question regarding Thread and Timer classes in Java
I have question regarding polymorphism about its assignment statement, for Example this is The

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.