<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Assuming a separate syntax, I believe that the criterion would be as simple as ensuring that no ValidateFoo constraints are left outstanding. The syntax would add the relevant validate call, and type variables involved in a ValidateFoo constraint would not be generalizable, and would have to be defaulted or inferred from elsewhere, similar to the monomorphism restriction. I'm not sure how difficult that would be to implement.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I'm not terribly gung ho on this, though. It feels very ad hoc. Making validation vs. non-validation syntactic rather than just based on polymorphism seems somewhat less so, though; so I'd prefer that direction. Finding unused syntax is always a problem, of course.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 11:38 AM, Ryan Trinkle <span dir="ltr"><<a href="mailto:ryan.trinkle@gmail.com" target="_blank">ryan.trinkle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">My greatest concern here would be that, as an application is maintained, a literal might go from monomorphic to polymorphic, or vice versa, without anybody noticing.  It sounds like this could result in a value silently becoming partial, which would be a big problem for application stability; in the opposite case - a partial value becoming a compile-time error - I am somewhat less concerned, but it could still be confusing and disruptive.<div><br></div><div>I would prefer that there be some syntactic indication that I want my literal to be checked at compile time.  This syntax could also add whatever monomorphism requirement is needed, and then it would become a compile-time error for the value to become polymorphic.  I don't know nearly enough about the type system to know whether this is possible.</div><div><br></div><div>Also, it seems to me that it might not be so clean as "monomorphic" versus "polymorphic".  For example, suppose I have this:</div><div><br></div><div>newtype PostgresTableName s = PostgresTableName String</div><div><br></div><div>where 's' is a phantom type representing the DB schema that the name lives in.  The validation function is independent of the schema - it simply fails if there are illegal characters in the name, or if the name is too long.  So, ideally, ("foo\0bar" :: forall s. PostgresTableName s) would fail at compile time, despite being polymorphic.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>Ryan</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 11:16 AM, Merijn Verstraaten <span dir="ltr"><<a href="mailto:merijn@inconsistent.nl" target="_blank">merijn@inconsistent.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ryan,<br>
<br>
Unfortunately, yes, you are understanding that correctly.<br>
<br>
The reason I qualified it with "monomorphic only" is that, I want to avoid breakage that would render the extension practically unusable in real code.<br>
<br>
Let's say I right now have:<br>
<br>
foo :: Num a => [a] -> [a]<br>
foo = map (+1)<br>
<br>
I have two options 1) we compile this as currently using fromIntegral and it WILL break for Even or 2) we reject any polymorphic use of literals like this. Given the amount of numerical code relying on the polymorphism of Num, I think the option of not being able to compile Num polymorphic code is completely out of the question. Almost no application  would work.<br>
<br>
I would advocate in favour of not requiring an IsList/IsString instance for the validation class, this would allow you to write a conversion that ONLY converts literals in a validated way and will never successfully convert literals without the extension, since with the extension disabled GHC would try to use the fromList/fromString from the IsString/IsList classes which do not exist.<br>
<br>
Unfortunately, given how deeply fromIntegral is tied to the Num class I don't see any way to achieve the same for Num. The only option would be to not make Even an instance of Num, that way the same trick as above could work. Removing fromIntegral from Num is obviously not going to happen and without doing that I don't see how we could prevent someone using fromIntegral manually to convert to Even in a way that won't break Num polymorphic functions. If you have any ideas on how to tackle this, I'm all open to hearing them!<br>
<br>
I agree with you that this is ugly, but I console myself with the thought that being able to check all monomorphic literals is already a drastic improvement over the current state. And in the case of lists and strings we could actually ensure that things work well, since almost no one writes "IsString polymorphic" code.<br>
<br>
Cheers,<br>
Merijn<br>
<div><div><br>
> On 6 Feb 2015, at 16:59, Ryan Trinkle <<a href="mailto:ryan.trinkle@gmail.com" target="_blank">ryan.trinkle@gmail.com</a>> wrote:<br>
><br>
> I think the idea of compile-time validation for overloaded literals is fantastic, and doing it with nicer syntax than quasiquoting would really improve things.  However, I'm a bit confused about specifically how the requirement that it be monomorphic will play into this.  For example, if I have:<br>
><br>
> x = 1<br>
><br>
> Presumably this will compile, and give a run-time error if I ever instantiate its type to Even.  However, if I have:<br>
><br>
> x :: Even<br>
> x = 1<br>
><br>
> it will fail to compile?  Furthermore, if I have the former, and type inference determines that its type is Even, it sounds like that will also fail to compile, but if type inference determines that its type is forall a. Nat a => a, then it will successfully compile and then fail at runtime.<br>
><br>
> Am I understanding this correctly?<br>
><br>
><br>
> Ryan<br>
><br>
> On Fri, Feb 6, 2015 at 8:55 AM, Erik Hesselink <<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>> wrote:<br>
> On Fri, Feb 6, 2015 at 2:49 PM, Dominique Devriese<br>
> <<a href="mailto:dominique.devriese@cs.kuleuven.be" target="_blank">dominique.devriese@cs.kuleuven.be</a>> wrote:<br>
> > Agreed.  For the idea to scale, good support for type-level<br>
> > programming with Integers/Strings/... is essential.  Something else<br>
> > that would be useful is an unsatisfiable primitive constraint<br>
> > constructor `UnsatisfiableConstraint :: String -> Constraint` that can<br>
> > be used to generate custom error messages. Then one could write<br>
> > something like<br>
> ><br>
> >   type family MustBeTrue (t :: Bool) (error :: String) :: Constraint<br>
> >   type family MustBeTrue True _ = ()<br>
> >   type family MustBeTrue False error = UnsatisfiableConstraint error<br>
> ><br>
> >   type family MustBeEven (n :: Nat) :: Constraint<br>
> >   type family MustBeEven n = MustBeTrue (IsEven n) ("Error in Even<br>
> > literal :'" ++ show n ++ "' is not even!")<br>
> ><br>
> >   instance (KnownNat n, MustBeEven n) => HasIntegerLiteral Even n where ...<br>
><br>
> Note that there is a trick to fake this with current GHC: you can<br>
> write an equality constraint that is false, involving the type level<br>
> string:<br>
><br>
> >   type family MustBeTrue False error = (() ~ error)<br>
><br>
> Erik<br>
> _______________________________________________<br>
> Glasgow-haskell-users mailing list<br>
> <a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
</div></div><br>_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
<br></blockquote></div><br></div>