ghciの:sprint
Haskellの値をThunkも加味して表示する
値の中身を表示する時に評価しない
そのためThunkは_として表示される
これはHaskellに遅延評価があるからある機能
docs
例
code:ghci(hs)
ghci> let x = 1 + 2 :: Int -- この状態ではxは未評価
ghci> :sprint x
x = _ -- xがthunkであることを確認できる
ghci> seq x () -- xを評価する
()
ghci> :sprint x
x = 3 -- xに値が評価済みであることを確認できる
例
code:ghci(hs)
ghci> x = 1..20 :: Integer
ghci> x !! 2
3
ghci> :sprint x
x = 1 : 2 : 3 : _ -- 4~20まではthunkであることを確認できる
#??
型を明示しないと行けないのはなんで?
let x = 1 + 2
x
:sprint x
だと、thunkのままになっている
関連
ghciの:print
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#ghci-cmd-:print
ghciの:sprintとだいたい同じだが、thunkに対して_t変数と型を表示する
ghciの:force
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#ghci-cmd-:force
thunkを評価してprintする
/mrsekut-book-4774183903/249 (4.3 評価を制御する)