[Haskell-cafe] Haskell trickery

Joel Reymont joelr1 at gmail.com
Tue Dec 20 05:08:18 EST 2005


Folks,

How is one to interpret the following? I'm particularly interested in  
the "IO $ \ s -> " notatoin as I have never seen that before.

allocaBytes :: Int -> (Ptr a -> IO b) -> IO b
allocaBytes (I# size) action = IO $ \ s ->
      case newPinnedByteArray# size s      of { (# s, mbarr# #) ->
      case unsafeFreezeByteArray# mbarr# s of { (# s, barr#  #) ->
      let addr = Ptr (byteArrayContents# barr#) in
      case action addr    of { IO action ->
      case action s       of { (# s, r #) ->
      case touch# barr# s of { s ->
      (# s, r #)
   }}}}}

Lemmih suggested that this is unrolling the code (manual inlining?)  
but how much speedup is that buying you?

Last but not least, what is

      case action addr    of { IO action ->
      case action s       of { (# s, r #) ->


	Thanks, Joel

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list