Opened 10 years ago

Closed 6 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 Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

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 6 years ago.
Fix comment in base.
0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_98.patch (2.1 KB) - added by michalt 6 years ago.
Patch for haskell98.
0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_2010.patch (2.1 KB) - added by michalt 6 years ago.
Patch for haskell2010.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 10 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 10 years ago by igloo

Milestone: 6.8

comment:3 Changed 10 years ago by igloo

Milestone: 6.8_|_

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 9 years ago by simonmar

Architecture: MultipleUnknown/Multiple

comment:5 Changed 9 years ago by simonmar

Operating System: MultipleUnknown/Multiple

comment:6 Changed 8 years ago by simonmar

difficulty: Easy (1 hr)Easy (less than 1 hour)

comment:7 Changed 7 years ago by mjg

Resolution: wontfix
Status: newclosed
Type of failure: None/Unknown

So this behaviour that is intended deviation from Haskell98.

comment:8 Changed 7 years ago by simonmar

Resolution: wontfix
Status: closednew

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

Changed 6 years ago by michalt

Fix comment in base.

Changed 6 years ago by michalt

Patch for haskell98.

Changed 6 years ago by michalt

Patch for haskell2010.

comment:9 Changed 6 years ago by michalt

Cc: michal.terepeta@… added
Status: newpatch

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 6 years ago by igloo

Resolution: fixed
Status: patchclosed

Applied, thanks.

Note: See TracTickets for help on using tickets.