Re: Proposal: ValidateMonoLiterals - Initial bikeshed discussion

I recall having some discussions with Mathieu Boespflug regarding how the static pointers work could be of use here. (And also Richard Eisenberg?) In particular, we want to demand a special property of our validation functions -- that they can safely be used at compile-time without necessarily "linking in the world" and invoking the whole of template haskell. A function that is "static" should in a sense have this sort of property? And so requiring that our validation functions be static seems like a useful thing from an implementation standpoint. Static semantics might also help "force the thunk" on what the correct relationship to polymorphism is. I guess the remaining question is then where to add them. I suppose we could stick them with special semantics on Num and IsString or the like and do it by magic? Alternately we could maybe have a whole class of "compile-time static functions" that we just explicitly use, and all have the property that they have type "a -> a" for some concrete "a", and that the value they are applied to is static. These functions are then applied at compile time, and forced to whnf. If they toss an error it is a compile error, otherwise they are not present in the generated code. There are other design variations possible, but that one feels pretty neat to me, if feasible. So then I could write foo :: Even foo = even 6 for example, and get errors at compile-time. On top of this we could add a special way to augment Num, IsString, etc with such methods to yield the desired: foo :: Even foo = 6 -gershom

This sounds rather similar to C++'s constexpr functions and I would totally be in favour for that sort of thing, but I figured that reusing Typed TH would be a less cumbersome way to implement this. If people are in favour of a more elaborate approach, I'm all ears, but I fear that might be out of my league to implement :) Cheers, Merijn
On 6 Feb 2015, at 21:54, Gershom B
wrote: I recall having some discussions with Mathieu Boespflug regarding how the static pointers work could be of use here. (And also Richard Eisenberg?) In particular, we want to demand a special property of our validation functions -- that they can safely be used at compile-time without necessarily "linking in the world" and invoking the whole of template haskell.
A function that is "static" should in a sense have this sort of property? And so requiring that our validation functions be static seems like a useful thing from an implementation standpoint. Static semantics might also help "force the thunk" on what the correct relationship to polymorphism is.
I guess the remaining question is then where to add them. I suppose we could stick them with special semantics on Num and IsString or the like and do it by magic?
Alternately we could maybe have a whole class of "compile-time static functions" that we just explicitly use, and all have the property that they have type "a -> a" for some concrete "a", and that the value they are applied to is static. These functions are then applied at compile time, and forced to whnf. If they toss an error it is a compile error, otherwise they are not present in the generated code.
There are other design variations possible, but that one feels pretty neat to me, if feasible.
So then I could write
foo :: Even foo = even 6
for example, and get errors at compile-time.
On top of this we could add a special way to augment Num, IsString, etc with such methods to yield the desired:
foo :: Even foo = 6
-gershom _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

Hi, Am Freitag, den 06.02.2015, 15:54 -0500 schrieb Gershom B:
I guess the remaining question is then where to add them. I suppose we could stick them with special semantics on Num and IsString or the like and do it by magic?
speaking about magic. This reminds me of https://ghc.haskell.org/trac/ghc/ticket/9180 which would add a function staticError that, if present in the core after RULES had processed, would emit a library author defined error at compile time. So if you can implement your validation in terms of RULES, then you can have RULES insert staticError expressions in the code if validation fails. In order to be useful for your purpose, you probably need the RULES mechanism beefed up a bit, e.g. to allow implications, “magic” predicates like "isLiteral" and some level of evaluation that might be beyond what’s possible now, and eventually lead to something like the static functions discussed in this thread, though. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org
participants (3)
-
Gershom B
-
Joachim Breitner
-
Merijn Verstraaten