I thought I could always put undefined in same place where I don't know yet what to put, and the code should compile fine, the error happening at run time only if that undefined is actually eveluated.
However, just in doing so I started writing something like
f = foldl undefined undefined undefined
in a file, and GHCi gives this error when I try to load the file
source.hs:3:7: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘foldl’
prevents the constraint ‘(Foldable t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Foldable (Either a) -- Defined in ‘Data.Foldable’
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
...plus one other
...plus 29 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: foldl undefined undefined undefined
In an equation for ‘f’: f = foldl undefined undefined undefined
|
3 | f = foldl undefined undefined undefined
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Which I interpret as "undefined does not typecheck here".
What is the rational behind this behavior, and what are the places where I cannot use undefined as a temporary placeholder?