Search code examples
haskelllambdaghci

How does one fix a "Variable not in scope" error?


Can you please help me understand the error and how to fix it?

comp = \x -> f(g(h(x)))

The error is

"Variable not in scope: f :: t0 -> t2"

for f, g and h, which they are just some functions not otherwise specified.


Solution

  • I suspect you're trying to build a function that composes 3 functions, much like how . composes 2 functions. To do that, you can't just make up names in the body and expect GHC to know what you meant by them. Instead, you need to bring them into scope somehow, like this: comp f g h = \x -> f(g(h(x)))