1
votes

I'm developing program in Haskell and for debug I've created file with some functions. A few functions I declarate how "underfined" and I'd like to set these function in interpreter (ghci).

For example:

r :: [String]
r = undefined

After loading this file in ghci (:load Experimental.hs), I use following command:

let r = "example string"

But I have the next exception:

"*** Exception: Prelude.undefined

Can I declarate in ghci function, which in source file (.hs) underfined? Or maybe exists other solutions?

1

1 Answers

7
votes

It is not possible, basically because it breaks referential transparency: after "setting" the function the result of some other function will be different. (You might argue that undefined raising an exception is clear enough for everything to be safe, but then you need some way to make sure no function with a proper first definition is redefined... it's all not worth the hassle.)

The correct way to do something like that is to make the undefined value an explicit argument of the function that uses it. Then you can just change this argument when invoking that function from the interpreter.