haskell – 为什么Parsec的uncons明确地内联了Text但不是ByteString?

前端之家收集整理的这篇文章主要介绍了haskell – 为什么Parsec的uncons明确地内联了Text但不是ByteString?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
There’s抽象层由Parsec使用,类型为Stream,它看起来像这样:
class (Monad m,ShowToken t) => Stream s m t | s -> t where
  uncons :: s -> m (Maybe (t,s))

instance (Monad m,ShowToken t) => Stream [t] m t where
  uncons []     = return Nothing
  uncons (t:ts) = return $Just (t,ts)
  {-# INLINE uncons #-}

instance Monad m => Stream CL.ByteString m Char where
  uncons = return . CL.uncons

instance Monad m => Stream C.ByteString m Char where
  uncons = return . C.uncons

instance Monad m => Stream T.Text m Char where
  uncons = return . T.uncons
  {-# INLINE uncons #-}

instance Monad m => Stream TL.Text m Char where
  uncons = return . TL.uncons
  {-# INLINE uncons #-}

我想知道内联是否是一个好主意,那么为什么在ByteString的Stream实例中没有内联?

所有这些功能应该是内联的还是没有的,或者Text和ByteString是如此不同,我们应该在一个内联,而不是内联另一个?

解决方法

我想没有真正的理由可能没有人注意,
基准,并表明有利于或反对{ – #INLINE# – }.

Stream文本实例在a commit from 2011添加
它带有{ – #INLINE# – } pragma.

另一方面,Stream ByteString was touched last time in Feb 2008,
之前的提交是从2008年1月初始导入.它没有任何INLINE编译指示

所以如果你认为有理由拥有或不拥有{ – #INLINE# – }编译指示
在这些情况下,使基准证明您的情况.我不知道有没有
任何.内联< *>可能是有意义的和>> =也是ParsecT.

相关:我最近添加了很少的内联编译,以清楚,因为基准清楚表明他们有所不同但OTOH你不应该把它们洒在一切上.

原文链接:https://www.f2er.com/html/230714.html

猜你在找的HTML相关文章