[ANN] ghc-typelits-knownnat-0.2: Solving GHCs KnownNat constraints

Hi, If you have ever worked with `GHC.TypeLits`, then you have probably encountered an error very similar to:
• Could not deduce (KnownNat (n + 2)) arising from a use of ‘natVal’ from the context: KnownNat n
i.e. where GHC cannot infer a `KnownNat (n+2)` constraint, even though a `KnownNat n` constraint is already given. Enter http://hackage.haskell.org/package/ghc-typelits-knownnat A type-checker plugin that can automatically derive "complex" KnownNat constraints from simpler ones. To use it, you simply add the {-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} pragma to the top of your file. If you want to know more, you can also check out the corresponding blog posts: http://qbaylogic.com/blog/2016/08/10/solving-knownnat-constraints-plugin.htm... http://qbaylogic.com/blog/2016/08/17/solving-knownnat-custom-operations.html Regards, Christiaan

I have to admit that is a heck of a lot easier to use than what I have: https://github.com/ekmett/constraints/blob/master/src/Data/Constraint/Nat.hs =) -Edward On Wed, Aug 17, 2016 at 9:11 AM, Christiaan Baaij < christiaan.baaij@gmail.com> wrote:
Hi,
If you have ever worked with `GHC.TypeLits`, then you have probably encountered an error very similar to:
• Could not deduce (KnownNat (n + 2)) arising from a use of ‘natVal’ from the context: KnownNat n
i.e. where GHC cannot infer a `KnownNat (n+2)` constraint, even though a `KnownNat n` constraint is already given.
Enter http://hackage.haskell.org/package/ghc-typelits-knownnat A type-checker plugin that can automatically derive "complex" KnownNat constraints from simpler ones.
To use it, you simply add the
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
pragma to the top of your file.
If you want to know more, you can also check out the corresponding blog posts:
http://qbaylogic.com/blog/2016/08/10/solving-knownnat-constr aints-plugin.html http://qbaylogic.com/blog/2016/08/17/solving-knownnat-custom -operations.html
Regards,
Christiaan _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Ah. I believe I have run into such issues with Clash, requiring me to add extraneous constraints over the results of addition. I assume this is the motivating use case here? Great work on this and Typelits-natnormalise! Will
On Aug 17, 2016, at 06:11, Christiaan Baaij
wrote:
If you have ever worked with `GHC.TypeLits`, then you have probably encountered an error very similar to:
• Could not deduce (KnownNat (n + 2)) arising from a use of ‘natVal’ from the context: KnownNat n

Yes, clash is the motivating use case. I wanted to simplify the API of the prelude for the upcoming 1.0 release. Especially to reduce monstrosities such as this: http://hackage.haskell.org/package/clash-prelude-0.10.11/docs/CLaSH-Sized-Fi... Cheers, Christiaan
On 17 Aug 2016, at 19:50, Will Yager
wrote: Ah. I believe I have run into such issues with Clash, requiring me to add extraneous constraints over the results of addition. I assume this is the motivating use case here?
Great work on this and Typelits-natnormalise!
Will
On Aug 17, 2016, at 06:11, Christiaan Baaij
wrote: If you have ever worked with `GHC.TypeLits`, then you have probably encountered an error very similar to:
• Could not deduce (KnownNat (n + 2)) arising from a use of ‘natVal’ from the context: KnownNat n
participants (3)
-
Christiaan Baaij
-
Edward Kmett
-
Will Yager