QualifiedDo with/to replace ApplicativeDo? - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Georgi Lyubenov // googleson78

Does anyone know of a way to use QualifiedDo to guarantee that my do-block will desugar with Applicative instead? Or to replace ApplicativeDo instead?
I tried this:

{-# LANGUAGE TypeFamilies #-}
module Ado where

(>>=) :: Int ~ Char => f a -> (a -> f b) -> f b
(>>=) = undefined

(<*>) :: Applicative f => f (a -> b) -> f a -> f b
(<*>) = (Prelude.<*>)

pure :: Applicative f => a -> f a
pure = Prelude.pure

return :: Applicative f => a -> f a
return = Prelude.pure

fmap :: Functor f => (a -> b) -> f a -> f b
fmap = Prelude.fmap

join :: Int ~ Char => m (m a) -> m a
join = undefined
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}

module Adotry where

import qualified Ado as A

newtype List a = List [a]
  deriving newtype (Show, Functor, Applicative)

xs :: List Int
xs = do
  x <- List [1,2,3]
  pure $ x

and the second module compiles and works fine (using ApplicativeDo, as it's forced by the lack of a Monad on List)
however, if I switch the do with an A.do, suddenly it doesn't compile anymore - due to the unsatisafiable Int ~ Char, or in other words, the Applicative methods are no longer used

Torsten Schmits

is there reason to assume QualifiedDo should work with Applicative?

Georgi Lyubenov // googleson78

and thanks, I "saw the error of my ways"

Georgi Lyubenov // googleson78

the issue was I wasn't using a qualified pure or return