import threading
mydata = threading.local()
def run():
# When will the garbage collector be able to destroy the object created
# here? After the thread exits from ``run()``? After ``join()`` is called?
# Or will it survive the thread in which it was created, and live until
# ``mydata`` is garbage-collected?
mydata.foo = object()
t = threading.Thread(target=run)
t.start()
t.join()
Run Code Online (Sandbox Code Playgroud) followng片段包含第69页练习3的解决方案(编写一个函数mean
来计算列表的平均值).
在编写一些QuickCheck测试以验证其结果是否更加清晰时,我发现在我的系统上(ghc 6.12.3,Haskell平台2010.2.0.0在32-但是Ubuntu 10.4),测试适用于Integer
输入,但不适用于Int
那些.有什么想法吗?
import Test.QuickCheck
-- From text and previous exercises
data List a = Cons a (List a)
| Nil
deriving (Show)
fromList :: [a] -> List a
fromList [] = Nil
fromList (x:xs) = Cons x (fromList xs)
listLength :: List a -> Int
listLength Nil = 0
listLength (Cons x xs) = 1 + listLength xs
-- Function ``mean`` is the aim of this exercise
mean :: (Integral …
Run Code Online (Sandbox Code Playgroud)