The following code won't compile and gives the error of
Couldn't match type ‘c1’ with ‘c’ ‘c1’ is a rigid type variable bound by a pattern with constructor: SomeReq :: forall c. Conn c => Req c -> SomeReq, in an equation for ‘run’
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ExistentialQuantification #-}
module Main where
import qualified Data.Text as T
class Conn c where
data Auth c :: *
data Env c :: *
data Req c :: *
getEnv :: Auth c -> IO (Env c)
runReq :: Env c -> Req c -> IO String
data SomeAuth = forall c. (Conn c) => SomeAuth (Auth c)
data SomeReq = forall c. (Conn c) => SomeReq (Auth c)
run :: SomeAuth -> SomeReq -> IO String
run (SomeAuth auth) (SomeReq req) = do
env <- getEnv auth
runReq env req
main :: IO ()
main = return ()
The reason for the existentials is that I need to store these data types in json. (Auth c)
and (Req c)
are always stored seperatly, but are always used together.
I'm assuming that the only possible way to make this work is to have some kind of runtime check to validate that these types match up. I'm not sure how to do that though.
c
is? Or isc
determined by the static structure of the code? – Fyodor Soikinc
is a service on which we can run the request. For example S3, or Google – whitehead1415