Ranges in Haskell and Purescript differ

Ranges in Haskell and Purescript actually give different results, but the doc (very end of https://github.com/purescript/documentation/blob/master/language/Differences-from-Haskell.md) does not mention this.

In Haskell (ghci):

Prelude> [1..0]
[]

Prelude> [0..1]
[0,1]

whereas in Purescript (0.11.7):

Array.range 1 0
[1,0]

Array.range 0 1
[0,1]

Needless to say, this is a pain when converting from Haskell to Purescript, so is there some Purescript range function which gives the same exact results as Haskell? In the meantime, I’ll write my own:

haskellRange :: Int -> Int -> Array Int
haskellRange start end =
    if start > end then [] else range start end

The Haskell syntax is sugar for Enum-based functions. You can find the equivalent in Data.Enum.
https://pursuit.purescript.org/packages/purescript-enums/4.0.0/docs/Data.Enum#v:enumFromTo

2 Likes