Skip to content

Commit

Permalink
#34, tag headErr/tailErr with Partial, and eta expand
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Jan 18, 2024
1 parent 82afb51 commit d55b09f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Changelog for Safe

#34, mark headErr/tailErr as Partial
0.3.20, released 2024-01-14
#34, add headErr, tailErr
#33, avoid using head/tail to avoid x-partial
Expand Down
8 changes: 4 additions & 4 deletions Safe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ at_ xs o | o < 0 = Left $ "index must not be negative, index=" ++ show o
--
-- > tailErr [] = error "Prelude.tail: empty list"
-- > tailErr [1,2,3] = [2,3]
tailErr :: [a] -> [a]
tailErr = tail
tailErr :: Partial => [a] -> [a]
tailErr x = tail x

-- | Identical to 'head', namely that fails on an empty list.
-- Useful to avoid the @x-partial@ warning introduced in GHC 9.8.
--
-- > headErr [] = error "Prelude.head: empty list"
-- > headErr [1,2,3] = 1
headErr :: [a] -> a
headErr = head
headErr :: Partial => [a] -> a
headErr x = head x

-- |
-- > tailMay [] = Nothing
Expand Down

0 comments on commit d55b09f

Please sign in to comment.