Skip to content

Instantly share code, notes, and snippets.

@nicuveo
Created May 27, 2021
Embed
What would you like to do?
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