Skip to content

Commit

Permalink
Annotate partial functions with HasCallStack
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jan 22, 2022
1 parent 191aa92 commit fc31ee0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Data/ByteString/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ cons c = \sbs -> let l = length sbs
-- An exception will be thrown in the case of an empty ShortByteString.
--
-- @since 0.11.3.0
last :: ShortByteString -> Word8
last :: HasCallStack => ShortByteString -> Word8
last = \sbs -> case null sbs of
True -> error "empty ShortByteString"
False -> indexWord8Array (asBA sbs) (length sbs - 1)
Expand All @@ -605,7 +605,7 @@ last = \sbs -> case null sbs of
-- Note: copies the entire byte array
--
-- @since 0.11.3.0
tail :: ShortByteString -> ShortByteString
tail :: HasCallStack => ShortByteString -> ShortByteString
tail = \sbs ->
let l = length sbs
nl = l - 1
Expand All @@ -618,7 +618,7 @@ tail = \sbs ->
-- An exception will be thrown in the case of an empty ShortByteString.
--
-- @since 0.11.3.0
head :: ShortByteString -> Word8
head :: HasCallStack => ShortByteString -> Word8
head = \sbs -> case null sbs of
True -> error "empty ShortByteString"
False -> indexWord8Array (asBA sbs) 0
Expand All @@ -630,7 +630,7 @@ head = \sbs -> case null sbs of
-- Note: copies the entire byte array
--
-- @since 0.11.3.0
init :: ShortByteString -> ShortByteString
init :: HasCallStack => ShortByteString -> ShortByteString
init = \sbs ->
let l = length sbs
nl = l - 1
Expand Down Expand Up @@ -761,31 +761,31 @@ foldr' k v = Foldable.foldr' k v . unpack
-- An exception will be thrown in the case of an empty ShortByteString.
--
-- @since 0.11.3.0
foldl1 :: (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1 :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1 k = List.foldl1 k . unpack
{-# INLINE foldl1 #-}

-- | 'foldl1'' is like 'foldl1', but strict in the accumulator.
-- An exception will be thrown in the case of an empty ShortByteString.
--
-- @since 0.11.3.0
foldl1' :: (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1' :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1' k = List.foldl1' k . unpack

-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,
-- and thus must be applied to non-empty 'ShortByteString's
-- An exception will be thrown in the case of an empty ShortByteString.
--
-- @since 0.11.3.0
foldr1 :: (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1 :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1 k = List.foldr1 k . unpack
{-# INLINE foldr1 #-}

-- | 'foldr1'' is a variant of 'foldr1', but is strict in the
-- accumulator.
--
-- @since 0.11.3.0
foldr1' :: (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1' :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1' k = \sbs -> if null sbs then errorEmptyList "foldr1'" else foldr' k (last sbs) (init sbs)
{-# INLINE foldr1' #-}

Expand Down

0 comments on commit fc31ee0

Please sign in to comment.