subtle inlining problem

Bulat Ziganshin bulat.ziganshin at
Thu Nov 9 06:50:47 EST 2006

Hello Simon,

Thursday, November 9, 2006, 11:29:18 AM, you wrote:

> I meant that I'm not 100% sure that an INLINE pragma in an
> *instance declaration* will cause the method to be inlined.  I think
> it works, but it'd be worth checking.

you may be sure - without this my deeply-classified Streams library
will be never such fast :)  once i lost INLINE pragma in the
middle-level definition and found that execution becomes 200x slower :)

altough really there are a several traps and i will try to document them
- may be it will be even possible to fix them. but basically it works
and it makes possible to write fast polymorhic code. believe it or
not, we already widely use this feature:

instance  Monad IO  where
    {-# INLINE return #-}
    {-# INLINE (>>)   #-}
    {-# INLINE (>>=)  #-}
    m >> k      =  m >>= \ _ -> k
    return x    = returnIO x

    m >>= k     = bindIO m k
    fail s      = failIO s

> Perhaps you could say that something magic happens when you, the
> programmer write x=y, and y has an INLINE pragma... but my instinct is to keep GHC's simple, rule.

my intuition says different but this is not very important, after all.
i can include this as one more caveat in the above-mentioned list

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at

More information about the Glasgow-haskell-users mailing list