Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Last active July 29, 2024 14:31
Show Gist options
  • Save ramirez7/41e7f4e48eb00de20c0b52911d62904a to your computer and use it in GitHub Desktop.
Save ramirez7/41e7f4e48eb00de20c0b52911d62904a to your computer and use it in GitHub Desktop.
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DataKinds #-}
import GHC.TypeLits
newtype SqlT m a = SqlT (m a)
deriving stock (Functor)
deriving newtype (Applicative, Monad)
runSqlT :: CanRunSqlT m => SqlT m a -> m a
runSqlT (SqlT ma) = ma
class CanRunSqlT m
instance {-# OVERLAPPABLE #-} CanRunSqlT m
instance TypeError (Text "Cannot runSqlT to SqlT") => CanRunSqlT (SqlT m)
{-
ghci> runSqlT (SqlT (pure ())) :: IO ()
ghci> runSqlT (SqlT (SqlT (pure ()))) :: SqlT (SqlT IO) ()
<interactive>:14:1: error: [GHC-64725]
• Cannot runSqlT to SqlT
• In the expression:
runSqlT (SqlT (SqlT (pure ()))) :: SqlT (SqlT IO) ()
In an equation for ‘it’:
it = runSqlT (SqlT (SqlT (pure ()))) :: SqlT (SqlT IO) ()
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment