小编Car*_*nte的帖子

Python中线程局部值的生命周期是什么时候?

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)

python multithreading

8
推荐指数
2
解决办法
2697
查看次数

Int和Integer的不同行为?

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)

haskell

0
推荐指数
1
解决办法
227
查看次数

标签 统计

haskell ×1

multithreading ×1

python ×1