Opened 7 years ago

Closed 3 years ago

#1182 closed bug (fixed)

splitAt does not implement H98 report behaviour, it is too strict in 'n'

Reported by: duncan Owned by:
Priority: normal Milestone:
Component: libraries/haskell98 Version: 6.6
Keywords: Cc: michal.terepeta@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The H98 report defines splitAt by:

splitAt :: Int -> [a] -> ([a],[a])
splitAt n xs = (take n xs, drop n xs)

So we would expect:

splitAt _|_ xs = (take _|_ xs, drop _|_ xs)

however GHC's implementation is strict in 'n', that is:

split _|_ xs = _|_

These cases can be distinguished with the expression:

case splitAt undefined [] of (_,_) -> ()

Hugs has the same problem. It defines splitAt by:

splitAt n xs | n <= 0 = ([],xs)
splitAt _ []          = ([],[])
splitAt n (x:xs)      = (x:xs',xs'') where (xs',xs'') = splitAt (n-1) xs

Perhaps for Haskell' we should make the report a little more lenient?

Attachments (3)

0001-Fix-a-comment-about-splitAt-fixes-1182.patch (906 bytes) - added by michalt 3 years ago.
Fix comment in base.
0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_98.patch (2.1 KB) - added by michalt 3 years ago.
Patch for haskell98.
0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_2010.patch (2.1 KB) - added by michalt 3 years ago.
Patch for haskell2010.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by duncan

Further investigation reveals that GHC, Hugs, nhc98 and Haskell 1.4 agree on the same behaviour. It is only Haskell98 that it out of step.

comment:2 Changed 7 years ago by igloo

  • Milestone set to 6.8

comment:3 Changed 7 years ago by igloo

  • Milestone changed from 6.8 to _|_

I don't think anyone thinks we should fix this by making GHC (and others) match the report, so _|_'ing this bug.

comment:4 Changed 6 years ago by simonmar

  • Architecture changed from Multiple to Unknown/Multiple

comment:5 Changed 6 years ago by simonmar

  • Operating System changed from Multiple to Unknown/Multiple

comment:6 Changed 4 years ago by simonmar

  • Difficulty changed from Easy (1 hr) to Easy (less than 1 hour)

comment:7 Changed 3 years ago by mjg

  • Resolution set to wontfix
  • Status changed from new to closed
  • Type of failure set to None/Unknown

So this behaviour that is intended deviation from Haskell98.

comment:8 Changed 3 years ago by simonmar

  • Resolution wontfix deleted
  • Status changed from closed to new

Before closing this we should document the difference, and possibly also fix it in the haskell98 and haskell2010 packages.

Changed 3 years ago by michalt

Fix comment in base.

Changed 3 years ago by michalt

Patch for haskell98.

Changed 3 years ago by michalt

Patch for haskell2010.

comment:9 Changed 3 years ago by michalt

  • Cc michal.terepeta@… added
  • Status changed from new to patch

I've changed the comment about splitAt in base. As for haskell98 and
haskell2010 I simply made them ignore splitAt from GHC.List and define it
themselves. Not sure if there's a better way to "fix" them..

comment:10 Changed 3 years ago by igloo

  • Resolution set to fixed
  • Status changed from patch to closed

Applied, thanks.

Note: See TracTickets for help on using tickets.