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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:23:57+00:00 2026-05-25T06:23:57+00:00

Why is the behavior of the Haskell range notation different for floats than for

  • 0

Why is the behavior of the Haskell range notation different for floats than for integers and chars?

Prelude> [1, 3 .. 10] :: [Int]
[1,3,5,7,9] 
Prelude> [1, 3 .. 10] :: [Float]
[1.0,3.0,5.0,7.0,9.0,11.0]
Prelude> ['a', 'c' .. 'f']
"ace"

I would understand it if the last element was close to the upper bound, but this is obviously not a rounding issue.

  • 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-25T06:23:57+00:00Added an answer on May 25, 2026 at 6:23 am

    The syntax [e1, e2 .. e3] is really syntactic sugar for enumFromThenTo e1 e2 e3, which is a function in the Enum typeclass.

    The Haskell standard defines its semantics as follows:

    For the types Int and Integer, the enumeration functions have the
    following meaning:

    • The sequence enumFrom e1 is the list [e1,e1 + 1,e1 + 2,…].
    • The sequence enumFromThen e1 e2 is the list [e1,e1 + i,e1 + 2i,…],
      where the increment, i, is e2 − e1. The increment may be zero or
      negative. If the increment is zero, all the list elements are the
      same.
    • The sequence enumFromTo e1 e3 is the list [e1,e1 + 1,e1 + 2,…e3].
      The list is empty if e1 > e3.
    • The sequence enumFromThenTo e1 e2 e3 is the list [e1,e1 + i,e1 +
      2i,…e3]
      , where the increment, i, is e2 − e1. If the increment is
      positive or zero, the list terminates when the next element would be
      greater than e3; the list is empty if e1 > e3. If the increment is
      negative, the list terminates when the next element would be less than
      e3; the list is empty if e1 < e3.

    This is pretty much what you’d expect, but the Float and Double instances are defined differently:

    For Float and Double, the semantics of the enumFrom family is given by the rules for Int above, except that the list terminates when the elements become greater than e3 + i∕2 for positive increment i, or when they become less than e3 + i∕2 for negative i.

    I’m not really sure what the justification for this is, so the only answer I can give you is that it is that way because it’s defined that way in the standard.

    You can work around this by enumerating using integers and converting to Float afterward.

    Prelude> map fromIntegral [1, 3 .. 10] :: [Float]
    [1.0,3.0,5.0,7.0,9.0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a Scala implementation of Haskell's groupBy. The behavior should be like
I'm beginning Haskell... I tried to write the following trivial function in two different
I thought expressions like this would cause Haskell to evaluate forever. But the behaviors
Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load : I have
The behavior I propose: A user loads up my search page, www.site.com/search, types their
Is behavior of SHA-1 algorithm defined for Unicode strings? I do realize that SHA-1
An example of unspecified behavior in the C language is the order of evaluation
Should entities have behavior? or not? Why or why not? If not, does that
Can you have smart behavior for the home key in Emacs? By smart I
I have encountered odd behavior when using document.getElementById tonight. Duplicated in Firefox 3 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.