Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Last active July 3, 2018 18:50
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 pbrisbin/47ad427ed4c421c21a29fff3a154e448 to your computer and use it in GitHub Desktop.
Save pbrisbin/47ad427ed4c421c21a29fff3a154e448 to your computer and use it in GitHub Desktop.
Persistent problems in LTS-11.15+
#!/usr/bin/env stack
-- stack script --resolver lts-10.8
-- vim: ft=haskell
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import ClassyPrelude
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sql
share [mkPersist sqlSettings, mkMigrate "migration"] [persistLowerCase|
User
name Text
|]
getUsers :: MonadIO m => SqlReadT m [Entity User]
getUsers = selectList [] []
main :: IO ()
main = undefined
#!/usr/bin/env stack
-- stack script --resolver lts-11.15
-- vim: ft=haskell
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import ClassyPrelude
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sql
share [mkPersist sqlSettings, mkMigrate "migration"] [persistLowerCase|
User
name Text
|]
-- • Couldn't match type ‘BaseBackend backend’ with ‘SqlBackend’
-- arising from a use of ‘selectList’
-- • In the expression: selectList [] []
-- In an equation for ‘getUsers’: getUsers = selectList [] []
--
-- |
-- 27 | getUsers = selectList [] []
-- | ^^^^^^^^^^^^^^^^
--
-- getUsers :: MonadIO m => SqlReadT m [Entity User]
-- getUsers = selectList [] []
-- The lts-11.15 definitions:
--
-- type SqlBackendCanRead backend
-- = ( BackendCompatible SqlBackend backend <-- TAKE NOTE
-- , PersistQueryRead backend
-- , PersistStoreRead backend
-- , PersistUniqueRead backend
-- )
-- type SqlReadT m a
-- = forall backend. SqlBackendCanRead' backend
-- => ReaderT backend m a
-- However, if I do this:
--
type SqlBackendCanRead' backend
= ( BaseBackend backend ~ SqlBackend -- <-- Only difference
, PersistQueryRead backend
, PersistStoreRead backend
, PersistUniqueRead backend
)
type SqlReadT' m a
= forall backend. SqlBackendCanRead' backend
=> ReaderT backend m a
-- And now this works!
getUsers :: MonadIO m => SqlReadT' m [Entity User]
getUsers = selectList [] []
main :: IO ()
main = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment