Skip to content

Instantly share code, notes, and snippets.

@nicuveo
Created May 27, 2021 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicuveo/d51114800d21bdd1a626ee027d5c15ef to your computer and use it in GitHub Desktop.
Save nicuveo/d51114800d21bdd1a626ee027d5c15ef to your computer and use it in GitHub Desktop.
TypeApplications bug?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Control.Monad.Reader
import Data.Kind (Type)
-- non-injective type family
class Foo a where
type Bar a :: Type
-- ambiguous class function
class Monad m => MonadFoo m where
doTheThing :: forall a. Bar a -> m (Bar a)
-- use of type application in function to disambiguate: ok
liftFoo :: forall a m t. (MonadFoo m, MonadTrans t) => Bar a -> t m (Bar a)
liftFoo v = lift $ doTheThing @m @a v
-- use of type application in instance to disambiguate: KO!
instance MonadFoo m => MonadFoo (ReaderT r m) where
doTheThing :: forall a. Bar a -> ReaderT r m (Bar a)
doTheThing = liftFoo @a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment