Make GHC ignore non-scope errors

I create a module where every time I write a function, it calls a dozen other functions that do not exist yet. Obviously, they will exist in the end, but it would be nice to do a syntax check before I finish writing the code.

Is there any combination of flags that I can use to generate GHC emission warnings, and not errors for "name foo out of scope"?

(It would be great if GHC could just select a type signature for nonexistent names and confirm that the program is still possible for type checking. This is almost what the "type hole" function does & mdash, but for that you still have to manually Define all identifiers.)

+6
source share
2 answers

Use the name TypedHoles :

 > let fx = _g . _h x $ x Found hole '_g' with type: b0 -> c Where: 'b0' is an ambiguous type variable 'c' is a rigid type variable bound by the inferred type of f :: s -> c at <interactive>:2:5 Relevant bindings include x :: s (bound at <interactive>:2:7) f :: s -> c (bound at <interactive>:2:5) In the first argument of '(.)', namely '_g' In the expression: _g . _h x In the expression: _g . _h x $ x Found hole '_h' with type: s -> s -> b0 Where: 'b0' is an ambiguous type variable 's' is a rigid type variable bound by the inferred type of f :: s -> c at <interactive>:2:5 Relevant bindings include x :: s (bound at <interactive>:2:7) f :: s -> c (bound at <interactive>:2:5) In the expression: _h In the second argument of '(.)', namely '_h x' In the expression: _g . _h x 

So this gives you _g :: b0 -> c and _h :: s -> s -> b0 with the context x :: s and f :: s -> c . A type checker can call these types most of the time (this is the point of TypedHoles ), and you can give them names. If you want, you can define all your functions with _ as the first character of the character name, and then use your editor to replace _(.+)\b with \1 . If you want to bypass the convention about the object using _name for the record field, just hover 2 underscores on the hole name.

This will still not allow you to compile the code, but if you use it in conjunction with -fdefer-type-errors , they will appear as warnings instead, allowing you to create type errors at runtime.

+11
source

My usual approach is to identify the missing functions or values ​​as undefined . It is easy to identify and leave you a convenient marker that this function has not yet been defined.

I know that this does not answer the OP question, since functions still need to be defined manually, but I thought it might be useful anyway.

+3
source

Source: https://habr.com/ru/post/984128/


All Articles