you did not give lst
a concrete type so for ghci it's a new instance/value every time you use it (and GHCi will choose a default type for it)
if you did not change anything you should even see a warning like this:
<interactive>:19:1: warning: [-Wtype-defaults]
• Defaulting the following constraints to type ‘Integer’
(Show a0) arising from a use of ‘print’ at <interactive>:19:1-10
(Num a0) arising from a use of ‘it’ at <interactive>:19:1-10
(Enum a0) arising from a use of ‘it’ at <interactive>:19:1-10
• In a stmt of an interactive GHCi command: print it
Add the :: [Int]
and it should work:
> let foo a b = a + b
> let bar c = c + 1
> let lst = [bar $ foo x y | y <- [0..9], x <- [0..9]] :: [Int]
> :sprint lst
lst = _
> seq lst ()
()
> :sprint lst
lst = _ : _
I like to think about generic types as having additional invisible parameters: the types for the type-parameters - so it's more a function then a value ;) (of course in reality it's not really exactly like this, but it helps me around issues like this)
EDIT as @dfeuer pointed out the comment about the parameters/invisible-functions might be misleading or even wrong.
Sadly I cannot claim to really know how GHCi deals with this (I'll gladly add something when I find a source) but so far my intuition would be, that GHCi does/cannot create a value till all dictionaries for the type-class constraints are known - so if there is no constraint it can and will create the value (at runtime there is no type so this is no problem).
In the above example the implicit Num
constraint (0
, 1
, 9
and +
) demands such an dictionary for the Num
instance of the involved type.