r/haskellquestions • • Apr 02 '20

how to ignore function my my source code?

Hi,

does anyone know whether I can ignore a function in my source code in Haskell?

addOne::Int -> Int
addOne = (+1)

How can make the compiler to ignore addOne in my source code without using comment syntax.

2 Upvotes

6 comments sorted by

5

u/nicuveo Apr 02 '20

What do you mean, "ignore"?

If you mean: not expose it to the rest of your code base, then you could have your module explicitly list what it exports, and not include that function.

If you mean: not give you warnings about it being unused, you could deactivate warnings about unused local functions (search for ghc options pragma).

If you mean: entirely skip it, as if it were not here at all, as if it were not code, so that you can compile your file even if that function is all wrong... Well, that's what comments are for, really; if you don't want the compiler to see it as code, there aren't a lot of other options.

I suppose you could also use the CPP language extension and put it in between a #if 0 and #endif, but that would be quite overkill.

0

u/ellipticcode0 Apr 02 '20

I want to modify the function and the ghc does not need to rebuild my code so ghc need to ignore my function completely.

4

u/tdammers Apr 02 '20

This is impossible.

Whether a function gets recompiled is decided on a per-file basis; any change to a source file, no matter how insignificant (even if it's just a single space appended to the end) will cause the toolchain to consider it "dirty", and it will be recompiled. Not just the functions you changed, but the entire module, as well as all modules that depend on it.

Per-function recompilation would be neat, but given the full complexity of GHC Haskell syntax, there is no way this could be done without doing most of the compilation work just to figure out function boundaries and deciding whether a change is significant - but if you're already running half the compilation pipeline, the advantage of then skipping bits is small, and facilitating it in the intermediate data structures would introduce a lot of complexity that just isn't worth it.

2

u/nicuveo Apr 02 '20

Put it in a different file, that is not part of your build?

1

u/zzantares Apr 05 '20

I think you'll be happier doing Clojure instead.

16

u/guaraqe Apr 02 '20

This seems to be a XY problem, what exactly do you want to do, that made you decide you need to ignore a function?