Why :sprint always prints a “_”?

前端 未结 3 2072
小鲜肉
小鲜肉 2020-11-30 12:31
Prelude> let a = 3
Prelude> :sprint a
a = _
Prelude> let c = \"ab\"
Prelude> :sprint c
c = _

Why does it always print a _?

3条回答
  •  鱼传尺愫
    2020-11-30 12:57

    I'm a bit late, but I had a similar issue:

    λ: let xs = [1,2,3]
    xs :: Num t => [t]
    λ: :sprint xs
    xs = _
    λ: print xs
    λ: :sprint xs
    xs = _
    

    This issue is specific to polymorphic values. If you have -XNoMonomorphismRestriction enabled ghci will never really evaluate/force xs, it'll only evaluate/force specializations:

    λ: :set -XMonomorphismRestriction
    λ: let xs = [1,2,3]
    xs :: [Integer]
    λ: print xs
    λ: :sprint xs
    xs = [1,2,3]
    

提交回复
热议问题