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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:03:54+00:00 2026-05-19T10:03:54+00:00

Today I started learning Haskell. I’m kind of new with functional languages, and I’m

  • 0

Today I started learning Haskell. I’m kind of new with functional languages, and I’m enjoying Haskell a lot.

However I’ve got a question about its design which is bugging me: from what I understood so far it looks like accessing an element to the back of a list is a lot more complicated that accessing the element to the front (something like xs:x where xs::[a] and x::a doesn’t seem to be possible).

(From what I understood) it’s possible to append a list to another one (xs++[a]), but it’ll cost more at run time (it requires to traverse the whole list) and it cannot be used for pattern matching.

Why is Haskell missing such operation?

  • 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-19T10:03:55+00:00Added an answer on May 19, 2026 at 10:03 am

    The list datatype

    data [a] = [] | a : [a]
    

    is defined like above. There’s only two patterns you can match: [] and x : xs, where x is the head and xs is the tail.

    Prepending to a list

    a = 1 : 2 : []
    b = 0 : a
    
     (:) <-- b
     / \  
    0  (:)  <-- a
       / \
      1  (:)
         / \
        2   []
    

    simply adds a new cons cell and reuses the original list as the tail.

    However, keep in mind that Haskell data structures are immutable. Appending to the tail of a list

    a = 1 : 2 : []
    b = a ++ [3]
    
     (:) <-- a      (:) <-- b
     / \            / \
    1  (:)         1  (:)
       / \            / \
      2   []         2  (:)
                        / \
                       3   []
    

    requires building an entirely new list, because no part of the original structure can be reused.

    In fact, consider

    a = 0 : a
    b = 0 : [ x+1 | x <- b ]
    
     (:) <-- a         (:) <-- b
     / \               / \
    0  (:) <-- a      0  (:) <-- [ x+1 | x <- b ]
       / \               / \
      0  (:) <-- a      1  (:) <-- [ x+1 | x <- [ x+1 | x <- b ] ]
         ...               ...
    

    How would you ever get the last element of the list, or append to the end?

    There are other data structures such as dequeues which are more suited for both front- and back-based access.

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

Sidebar

Related Questions

I am new with wordpress. I have started learning wordpress from today. I went
So I started learning Scala today and I got all my vim config files
I am new to python and just started learning it today. I have installed
I'm new to Scala ,just started learning it today.I would like to know how
Today I started thinking about a new project, and I found one. The goal
I am very new (started today) to writing chrome extensions but need to write
I started reading about underscore.js today, it is a library for javascript that adds
I started writing functional tests for my rails app today. I use the RESTful
I started learning vim today and installed it using sudo apt-get install vim Now,
So I started learning C today, and as an exercise I was told to

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.