でネストされた変数の推定型を出力する方法はありますghci
か? コードを考えてみましょう。
let f = g where
g (x :: Int) = x
次に、 のタイプを照会するとよいでしょう。g
たとえば、:t f.g
が出力されInt -> Int
ます。
適切に間違った型の注釈を付けて、エラー メッセージを確認することで、この情報を引き出すことができます。
*Main> let f = g where g::a; g (x::Int) = x
<interactive>:1:23:
Couldn't match type `a1' with `Int -> Int'
`a1' is a rigid type variable bound by...
ghci デバッガーは、適切に配置されたブレークポイントを使用して出力できます (ただし、モジュール内に定義をロードする必要があります)。
{-# LANGUAGE ScopedTypeVariables #-}
f a = g a where
g (x :: Int) = x
次にghciで:
Prelude> :l tmp2.hs
[1 of 1] Compiling Main ( tmp2.hs, interpreted )
Ok, modules loaded: Main.
*Main> :b 3 9
Breakpoint 0 activated at tmp2.hs:3:7-9
*Main> f undefined
Stopped at tmp2.hs:3:7-9
_result :: Int = _
a :: Int = _
g :: Int -> Int = _
[tmp2.hs:3:7-9] *Main>