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

  • Home
  • SEARCH
  • 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 9022177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:23+00:00 2026-06-16T05:26:23+00:00

I need to create stack data type in haskell to be able to write

  • 0

I need to create stack data type in haskell to be able to write like this:

let a = emptyStack

push 10 a
//[10]

pop a 
[]

I want push to look like

push :: a -> Stack a -> Stack a
push a b = a:b

but I have problems with syntax, exactly how to declare this new data type, so that

let a = emptyStack 
:t a

would show Stack

any hints on syntax

  • 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-16T05:26:25+00:00Added an answer on June 16, 2026 at 5:26 am

    Let’s look at your implementation for push. It uses the operator :. You can find out the type of that operator like this:

    ghci> :t (:)
    (:) :: a -> [a] -> [a]
    

    So this operator takes an a (which represents an arbitrary type), and a sequence of as, and returns the updated sequence. So your type Stack needs to be a sequence.

    type Stack a = [a]
    

    If you then define emptyStack like this:

    emptyStack :: Stack a
    emptyStack = []
    

    You’ll get the result you’re looking for.

    ghci> :t a
    a :: Stack a
    

    With that help, I think you’ll be able to figure out how to write pop.

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

Sidebar

Related Questions

Suppose I'd want to create a new data type and make the constructors showable,
I want to implement push and pop operations in LLVM assembly. The alloca instruction
so I want to use this JQuery plugin that Stack Overflow has made available
I need to create an interface like the below: Each block represents a client's
In .NET, integer data type is a value type(stack) and String is a reference
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass

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.