作者joshs (Josh Ko)
看板PLT
標題Re: [問題] '#'的意思
時間Sun Dec 30 19:49:40 2012
※ 引述《etwas (i'm only dust)》之銘言:
: 各位版友好
: 想請問在source code中 '(#', '#)'是什麼意思? 例如:
: instance Monad (ST s) where
: return x = ST (\ s -> (# s, x #))
: 這在哪裡的文件有提到呢?
: 謝謝
這是 GHC 的 unboxed tuples:
Unboxed tuples are used for functions that need to return
multiple values, but they avoid the heap allocation normally
associated with using fully-fledged tuples. When an unboxed
tuple is returned, the components are put directly into
registers or on the stack; the unboxed tuple itself does not
have a composite representation. Many of the primitive
operations listed in primops.txt.pp return unboxed tuples.
In particular, the IO and ST monads use unboxed tuples to
avoid unnecessary allocation during sequences of operations.
以上摘自
http://www.haskell.org/ghc/docs/latest/html/users_guide/primitives.html
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 86.2.123.53
1F:→ etwas:感謝解惑! 12/31 08:06