Haskell “为什么?”;“固定”;占用这么多内存?

Haskell “为什么?”;“固定”;占用这么多内存?,haskell,memory,Haskell,Memory,我使用了以下代码: fix' f = let x = f x in x 然后就跑了 > :set +s > fix' (const 'u') 只为了得到: 'u' (0.00 secs, 83,512 bytes) 为什么这需要这么多的记忆 我的评估如下: fix' f = let x = f x in x fix' (const 'u') let x = const 'u' x in x const _ x = x const 'u' undefined 'u' 这当然是一

我使用了以下代码:

fix' f = let x = f x in x
然后就跑了

> :set +s
> fix' (const 'u')
只为了得到:

'u'
(0.00 secs, 83,512 bytes)
为什么这需要这么多的记忆

我的评估如下:

fix' f = let x = f x in x
fix' (const 'u')
let x = const 'u' x in x
const _ x = x
const 'u' undefined
'u'

这当然是一种效率极低的格式,但ASCII编码只需要105字节,加上用于比较的内存使用量可能仍然无法达到
fix
示例中的使用量。

在GHCi中,
'u'
本身就已经消耗了一些KBs,因为它代表
putStrLn(show'u')
,与GHC不同的是,所有内容都会被解释,不会进行任何优化。只需对
'u'
进行测试,然后比较内存,看看
fix
是否是真正的问题,