packages feed

magic-tyfams 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+61/−18 lines, 3 files

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for type-sets +## 0.1.0.1 --- 2019-08-05++Update documentation+ ## 0.1.0.0 --- 2019-08-05  Initial release!
README.md view
@@ -1,33 +1,72 @@-# cmptype+# magic-tyfams  ## Dedication -> Comparison is an act of violence against the self.+> G.O.B.: Two drowned white doves from "Flowers to Doves," a rabbit from "Doves+>   to Rabbit," also drowned. These were mice... >-> Iyanla Vanzant+> Tobias: From "Rabbit to Mice?"+>+> G.O.B.: No. That can't be done. No, these were a part of something I call+>   *mice-cellaneous*: "Mouse in Purse." "Mouse in Drink." Here's a mouse, now+>   it's gone...+>+> --Arrested Development   ## Overview -`cmptype` provides a magical type family that lets you compare types:+`magic-tyfams` writes the annoying parts of GHC plugins do you don't have to. It+provides a convenient interface for implementing magical type families. +For example, consider the following definition in `mypackage` of an always-stuck+type family:+ ```haskell+module Some.Module where+ type family CmpType (a :: k) (b :: k) :: Ordering ``` -When you turn on the `-fplugin=Type.Compare.Plugin` flag, it will let you-compare arbitrary types. Why would you want such a thing? Probably because you-want to write a type-level container that isn't a fucking list!+We can generate a plugin that will solve this: +```haskell+module Some.Plugin where +plugin :: Plugin+plugin = magicTyFamPlugin "mypackage"+                          "Some.Module"+                          "CmpType" $+  withStuckSemantics $ \[_k, a, b] ->+    pure $ promoteOrdering $ nonDetCmpType a b+++promoteOrdering :: Ordering -> Type+promoteOrdering = flip mkTyConApp [] . \case+   LT -> promotedLTDataCon+   EQ -> promotedEQDataCon+   GT -> promotedGTDataCon+```++Enabling this plugin via `-fplugin=Some.Plugin` will now automagically solve+`CmpType`! Nice!++```haskell+{-# OPTIONS_GHC -fplugin=Some.Plugin #-}++import Proxy++-- compiles just fine!+test :: Proxy (CmpType Int Int) -> Proxy 'EQ+test = id+```++ ## Acknowledgments -Big thanks to [Boris Rozinov][oofp] for the initial idea, and for making as much-coffee as I could drink while I wrote it. Also thanks to [Christiaan-Baaij][chistiaanb] and [Matt Pickering][mpickering] for their indispensable help-convincing GHC to do the right thing here.+Thanks to [Christiaan Baaij][chistiaanb] and [Matt Pickering][mpickering] for+their indispensable help convincing GHC to do the right thing here. -[oofp]: https://github.com/oofp [chistiaanb]: https://christiaanb.github.io/ [mpickering]: http://mpickering.github.io/ 
magic-tyfams.cabal view
@@ -4,15 +4,15 @@ -- -- see: https://github.com/sol/hpack ----- hash: d2d7b9baf0c8c55312fee132eb5e0fbb0487626c4739f5510005a60ed17a8cd4+-- hash: e1b2ac16f5e9b1a093d84bb270c518375d731def7109a32c13456b688c03d4f1  name:           magic-tyfams-version:        0.1.0.0+version:        0.1.0.1 synopsis:       Write plugins for magic type families with ease-description:    Please see the README on GitHub at <https://github.com/isovector/type-sets/tree/master/cmptype#readme>+description:    Please see the README on GitHub at <https://github.com/isovector/type-sets/tree/master/magic-tyfams#readme> category:       Compiler Plugin-homepage:       https://github.com/https://github.com/isovector/type-sets/tree/master/cmptype#readme-bug-reports:    https://github.com/https://github.com/isovector/type-sets/tree/master/cmptype/issues+homepage:       https://github.com/https://github.com/isovector/type-sets/tree/master/magic-tyfams#readme+bug-reports:    https://github.com/https://github.com/isovector/type-sets/tree/master/magic-tyfams/issues author:         Sandy Maguire maintainer:     sandy@sandymaguire.me copyright:      2019 Sandy Maguire@@ -25,7 +25,7 @@  source-repository head   type: git-  location: https://github.com/https://github.com/isovector/type-sets/tree/master/cmptype+  location: https://github.com/https://github.com/isovector/type-sets/tree/master/magic-tyfams  library   exposed-modules: