INLINE Pragma in combination with type classes

Given the following code (copied from the attoparsec library) what does the inline pragma do? I suppose it makes sense for only fmapR to be inlined, but not the other fmap s which are defined in other Functor instances.

instance Functor (IResult t) where
    fmap = fmapR
    {-# INLINE fmap #-}

The inline pragma will copy the contents of the function (in this case fmapR ) to the location where it is called, if the compiler can prove that the functor being used is IResult .

The function cannot be inlined in the following case, because the definition of fmap is not known:

f :: Functor f => f Int -> f Float
f = fmap fromIntegral

Here, however, it is known, because a certain functor is being used, and the function can be inlined:

f :: IResult Int -> IResult Float
f = fmap fromIntegral
-- rewritten to: f = fmapR fromIntegral; might be further inlined
链接地址: http://www.djcxy.com/p/58552.html

上一篇: 命名空间模型在Rails应用程序中

下一篇: INLINE Pragma与类型类相结合