Skip to content

Instantly share code, notes, and snippets.

@KingoftheHomeless
Last active November 23, 2018 18:12
Show Gist options
  • Save KingoftheHomeless/e8463a42963c1c5e27c3482529c66447 to your computer and use it in GitHub Desktop.
Save KingoftheHomeless/e8463a42963c1c5e27c3482529c66447 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DerivingVia, StandaloneDeriving, PolyKinds, RankNTypes #-}
module DerivingViaPolyKinds where
class Foo (f :: k -> *)
newtype Bar (f :: k -> *) (a :: k) = Bar (f a)
-- deriving Foo via f -- Works
-- Standalone deriving instances only work if you instantiate the polykinded variable:
-- deriving via (f :: * -> *) instance Foo f => Foo (Bar f)
-- deriving via (f :: (* -> *) -> *) instance Foo f => Foo (Bar f)
-- None of these work:
{-
deriving via f instance Foo f => Foo (Bar f)
deriving via (f :: k -> *) instance Foo f => Foo (Bar f)
deriving via (f :: k -> *) instance Foo (f :: k -> *) => Foo (Bar f)
deriving via (f :: k -> *) instance Foo f => Foo (Bar (f :: k -> *))
deriving via (f :: k -> *) instance Foo (f :: k -> *) => Foo (Bar f :: k -> *)
deriving via f instance Foo (f :: k -> *) => Foo (Bar f)
deriving via f instance Foo (f :: k -> *) => Foo (Bar f :: k -> *)
forall-ing won't help.
forall k. on the LHS interprets it as an RankNType
forall k. on the RHS interprets it a universally quantified variable free from the LHS.
deriving via (forall k. f :: k -> *) instance Foo (f :: k -> *) => Foo (Bar f :: k -> *)
deriving via (forall k. f :: k -> *) instance Foo f => Foo (Bar f)
deriving via (forall f k. f :: k -> *) instance Foo (f :: k -> *) => Foo (Bar f :: k -> *)
deriving via (forall f k. f :: k -> *) instance Foo f => Foo (Bar f)
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment