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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:46+00:00 2026-05-27T14:49:46+00:00

According to the Haskell 2010 report , init is defined as the following: init

  • 0

According to the Haskell 2010 report, init is defined as the following:

init             :: [a] -> [a]  
init [x]         =  []  
init (x:xs)      =  x : init xs  
init []          =  error "Prelude.init: empty list"

base-4.4.1.0 defines it similarly. To me, it seems that it would be perfectly acceptable and intuitive to have:

init [] = []

which would make init a total function. Since this definition made it into the haskell 2010 report I guess that there are arguments for it. Is that the case or is it defined that way because of tradition and backwards compatibility?

  • 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-27T14:49:47+00:00Added an answer on May 27, 2026 at 2:49 pm

    The same reason tail [] isn’t []; it breaks the invariants that define these functions. We can define head and tail by saying that if head and tail are defined for a value xs, then xs ≡ head xs : tail xs.

    As Niklas pointed out, the invariant we want to define init and last is xs ≡ init xs ++ [last xs]. It’s true that last isn’t defined on empty lists either, but why should last be defined if init can’t be? Just like it would be wrong if one of head or tail was defined on an input while the other wasn’t, init and last are two sides of the same coin, splitting a list into two values that together are equivalent to the original.

    For a more “practical” view (although being able to reason about programs in terms of useful invariants about the operations they use has very practical benefit!), an algorithm that uses init will probably not behave correctly on an empty list, and if init worked that way, it would work to hide the errors produced. It’s better for init to be conservative about its inputs so that consideration has to be given for edge-cases like empty list when it is used, especially when it isn’t at all clear that the proposed value for it to return in those cases is reasonable.

    Here’s a previous Stack Overflow question about head and tail, including why tail [] doesn’t just return []; the answers there should help to explain why these invariants are so important.

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

Sidebar

Related Questions

According to what I have found so far, I can use the following code:
According to a number of tutorials (including Real World Haskell) one can, using ghci
I set up a project according to the recommendation here: http://www.haskell.org/haskellwiki/Structure_of_a_Haskell_project How can I
I wish to compress my application's network traffic. According to the (latest?) Haskell Popularity
I'm running CentOS 5.5 and I want to install the Haskell Platform there. According
According to this discussion , the iphone agreement says that it doesn't allow loading
According to the manual , git dcommit will create a revision in SVN for
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to
According to MSDN form.RightToLeftLayout = True; form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False; is
According to select name from system_privilege_map System has been granted: SELECT ANY TABLE ...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.