<div dir="ltr">Despite appearances the above code doesn't need overlapping instances, as the KnownNat n constraint forces (n :: Nat), while the existing instances are all in *.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 4, 2016 at 4:00 AM, Edward Kmett <span dir="ltr"><<a href="mailto:ekmett@gmail.com" target="_blank">ekmett@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">This could be done in a backwards compatible way by making the HasResolution class polykinded.<div><br></div><div>{-# LANGUAGE PolyKinds, ScopedTypeVariables, DataKinds #-}</div><div>import Data.Proxy</div><div><br></div><div>instance KnownNat n => HasResolution n where</div><div> resolution _ = natVal (Proxy :: Proxy n)</div><div><div><br></div><div>Then we could just keep the existing Exx for backwards compatibility or for folks who want portable code, and folks who want the fancier API can have it. Not only that but with `reflection` they could safely generate precision types dynamically at runtime if it was an unknown. Not a bad return on investment for 3 lines of code!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Edward</div><div><br></div></font></span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 4, 2016 at 3:38 AM, Erik Hesselink <span dir="ltr"><<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If Data.Fixed in base is changed, might it make more sense to switch<br>
to type level naturals and KnownNat as a class? It implements exactly<br>
the same functionality but in a more readable and general way.<br>
<span><font color="#888888"><br>
Erik<br>
</font></span><div><div><br>
On 3 August 2016 at 19:46, Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@gmail.com</a>> wrote:<br>
> Thanks for your response. I'm actually already doing you recommended in my<br>
> library. It does work, but I still think it would be better to have this in<br>
> base.<br>
><br>
> -Andrew Martin<br>
><br>
> On Wed, Aug 3, 2016 at 11:46 AM, Merijn Verstraaten <<a href="mailto:merijn@inconsistent.nl" target="_blank">merijn@inconsistent.nl</a>><br>
> wrote:<br>
>><br>
>> Hi Andrew,<br>
>><br>
>> Data.Fixed actually already provides all the tools you need to support any<br>
>> arbitrary precision. As such, I don't see the need to add obscure precisions<br>
>> to the library in addition to the existing common ones. Using Data.Fixed<br>
>> with a 4 digit precision like you want can be achieved in 3 lines of code in<br>
>> you geolite library. Simply define:<br>
>><br>
>> data MyPrecision<br>
>> instance HasResolution MyPrecision where<br>
>> resolution _ = 4<br>
>><br>
>> and use "Fixed MyPrecision" as type in your library. As you can see in the<br>
>> haddocks, the Num, Real, RealFrac, etc. instances work for any arbitrary<br>
>> instance of HasResolution.<br>
>><br>
>> Cheers,<br>
>> Merijn<br>
>><br>
>> > On 3 Aug 2016, at 13:57, Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@gmail.com</a>><br>
>> > wrote:<br>
>> ><br>
>> > I've been working on a library for parsing geolite's GeoIP csv file<br>
>> ><br>
>> > (<a href="http://hackage.haskell.org/package/geolite-csv-0.2/docs/Geolite-Types.html" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/geolite-csv-0.2/docs/Geolite-Types.html</a>).<br>
>> > In this file, the latitude and longitude are always given to four<br>
>> > decimal points of precision. It seems like the Fixed data type (from<br>
>> > Data.Fixed in base) is the best choice for representing this.<br>
>> ><br>
>> > However, the precision levels provided are:<br>
>> ><br>
>> > - E0<br>
>> > - E1<br>
>> > - E2<br>
>> > - E3<br>
>> > - E6<br>
>> > - E9<br>
>> > - E12<br>
>> ><br>
>> > I would like to propose adding all of the missing ones into Data.Fixed<br>
>> > as well. Even though needed a four-decimal-point-precision number is<br>
>> > uncommon, it's not unheard of. Admittedly, the precision offered by E11<br>
>> > seems unlikely to ever be needed, but I think it would be nice for<br>
>> > completeness. I would be happy to PR this if others agree that it's a<br>
>> > good idea.<br>
>> ><br>
>> > -Andrew Martin<br>
>> ><br>
>> > _______________________________________________<br>
>> > Libraries mailing list<br>
>> > <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
>> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> -Andrew Thaddeus Martin<br>
><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>