Opened 13 months ago

Last modified 3 months ago

#9180 new feature request

New magic function `staticError`

Reported by: nomeata Owned by: nomeata
Priority: normal Milestone:
Component: Compiler Version: 7.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9637 Differential Revisions:

Description

While playing games with RULES, I had the need for a way to tell the compiler “please spit out an error message”, in my case if list fusion fails where the user explicitly requested for it.

Currently I put an error "List did not fuse" in the code using a RULE, but what I’d really like to do is to put in a staticError "List did not fuse" that, if appearing in Core (say, after the final simplification) causes GHC to abort and print this message.

(I’m tempted to use type level strings somehow to make sure that the parameter to staticError is not present at the value level, and also that the string is easier to obtain. I’ll see.)

Change History (4)

comment:1 Changed 13 months ago by simonpj

I'd be happy with something like this, provided

  • It's reported by Lint
  • It has runtime behaviour too (in case you don't run Lint)

Of course I could be wrong about this, but making it another Lint check seems right to me.

Simon

comment:2 Changed 9 months ago by nomeata

Lint is not run by default, is it?

In that case I don’t think it would quite cut it. I imagine that staticError could be quite a general tool that library authors can use to warn unaware users when they use the library wrongly; a user that deliberately runs the linter is, by definition, not unaware.

Another use case would be to have rules that detect certain patterns that the library author knows that do not make sense, by having a rule foo doNotPassMeToFoo = staticError "Bad user!" he could prevent that. (Of course we’d like library authors to use the type system for that, but that might not be possible in all cases...)

comment:3 Changed 9 months ago by simonpj

My guess is that you'll be plagued with false positives, but you can try.

comment:4 Changed 3 months ago by goldfire

See also #9637 for a type-level variant of this idea.

Note: See TracTickets for help on using tickets.