Skip to content

Ineffective INLINE pragmas on many method for Alternative Get instance. #196

@AndreasPK

Description

@AndreasPK

Binary defines this instance:

-- | @since 0.7.0.0
instance Alternative Get where
  empty = C $ \inp _ks -> Fail inp "Data.Binary.Get(Alternative).empty"
  {-# INLINE empty #-}
  (<|>) f g = do
    (decoder, bs) <- runAndKeepTrack f
    case decoder of
      Done inp x -> C $ \_ ks -> ks inp x
      Fail _ _ -> pushBack bs >> g
      _ -> error "Binary: impossible"
  {-# INLINE (<|>) #-}
  some p = (:) <$> p <*> many p
  {-# INLINE some #-}
  many p = do
    v <- (Just <$> p) <|> pure Nothing
    case v of
      Nothing -> pure []
      Just x -> (:) x <$> many p
  {-# INLINE many #-}

But since many is recursive GHC will never inline it making the INLINE pragma ineffective.

If that's fine it could be made INLINEABLE instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions