Closed treeowl closed 6 years ago
By the way: it is also quite possible to make ContT
work with this sort of thing. Unfortunately, that means convincing Ross Paterson to do it.
The levity polymorphism seems to work out to be free.
On the other hand, the PolyKinds
can wind up with many potential instances becoming flexible
Consider the following fairly artificial example,
instance (Applicative f, Monoid m) => Monoid (Codensity f m)
It wasn't flexible before PolyKinds
were added, but afterwards, (as shown by haddock)
instance (Applicative f, Monoid m) => Monoid (Codensity * f m)
is a flexible instance. So until something monomorphizes the kind of the argument, the instance isn't selectable, leading to more situations where instance selection gets stuck.
At present, IIRC, we already have PolyKinds
turned on, so we've already paid this latter cost.
Good point. Perhaps we should unflex the instances by fixing the kind in the constraint where appropriate?
The reason I accepted the original proposal to adopt PolyKinds
for this data type was that as I recall, none of the existing instances happened to run afoul of this issue, but its a thing I consider whenever I get an enthusiastic email asking me to PolyKind all the things.
Maybe I got the version wrong...
On Mar 13, 2018 8:39 AM, "Ryan Scott" notifications@github.com wrote:
@RyanGlScott commented on this pull request.
I didn't notice this until it was merged—one minor comment.
In src/Control/Monad/Codensity.hs https://github.com/ekmett/kan-extensions/pull/52#discussion_r174112973:
import Data.Typeable
endif
+#if __GLASGOW_HASKELL__ >= 802 +import GHC.Exts (TYPE)
Levity polymorphism has been around since GHC 8.0—is there a reason you only enabled it on 8.2 or later?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ekmett/kan-extensions/pull/52#pullrequestreview-103408988, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_YkEb6rQiiZyzfh7TYYpC_GpsxDpks5td74LgaJpZM4SoGqw .
@RyanGlScott, FYI, in a new PR, I tried 8.0 and the compiler panicked. TypeInType
was pretty experimental then.
Ah! Thanks for confirming.
@ekmett Is this at all better than the flexible version?
instance (f ~~ f', Applicative f', Monoid m) => Monoid (Codensity (f::k -> Type) m)
I submitted a PR suggesting this approach. I think it works for everything except MonadTrans.
On Mar 16, 2018 3:39 PM, "Icelandjack" notifications@github.com wrote:
@ekmett https://github.com/ekmett Is this at all better than the flexible version?
instance (f ~~ f', Applicative f', Monoid m) => Monoid (Codensity (f::k -> Type) m)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ekmett/kan-extensions/pull/52#issuecomment-373823634, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_f1hfjJx12VPtO94rPcj-R3IDqhyks5tfBUDgaJpZM4SoGqw .
Great! #53
With
TypeInType
, we can getI don't know if the polymorphism in
k
is useful; it was readily available, so I took it. I actually have an application in mind for polymorphism inrep
. Theprimitive
package offersNow what if I want to recover the underlying functionality of
indexArray#
from that? One option would be to use thedata Box a = Box a
"lifted identity" monad. Another would be to use a custom-writtenCont
monad (a clone of the one fromtransformers
). But I realized thatCodensity
almost works off the shelf, if we just add a bit of extra polymorphism. With this patch, I can writeand get exactly the Core I want