haskell mocking: define func in datatype with class-constraint
up vote
2
down vote
favorite
there is the function
httpLBS :: MonadIO m => Request -> m (Response ByteString)
in the Network.HTTP.Simple module (doc), which i want to pass around (for mocking later in integration-testing) with my Ctx data-object
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: MonadIO m => Request -> m (Response ByteString)
} deriving (Show)
but I'm getting this error:
Prelude> :l Context.hs
[1 of 1] Compiling Context ( Context.hs, interpreted )
Context.hs:19:32: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Context.hs:19:48: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Failed, no modules loaded.
how is it possible to define this method in my Ctx data-type correctly??
haskell
add a comment |
up vote
2
down vote
favorite
there is the function
httpLBS :: MonadIO m => Request -> m (Response ByteString)
in the Network.HTTP.Simple module (doc), which i want to pass around (for mocking later in integration-testing) with my Ctx data-object
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: MonadIO m => Request -> m (Response ByteString)
} deriving (Show)
but I'm getting this error:
Prelude> :l Context.hs
[1 of 1] Compiling Context ( Context.hs, interpreted )
Context.hs:19:32: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Context.hs:19:48: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Failed, no modules loaded.
how is it possible to define this method in my Ctx data-type correctly??
haskell
4
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
1
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
there is the function
httpLBS :: MonadIO m => Request -> m (Response ByteString)
in the Network.HTTP.Simple module (doc), which i want to pass around (for mocking later in integration-testing) with my Ctx data-object
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: MonadIO m => Request -> m (Response ByteString)
} deriving (Show)
but I'm getting this error:
Prelude> :l Context.hs
[1 of 1] Compiling Context ( Context.hs, interpreted )
Context.hs:19:32: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Context.hs:19:48: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Failed, no modules loaded.
how is it possible to define this method in my Ctx data-type correctly??
haskell
there is the function
httpLBS :: MonadIO m => Request -> m (Response ByteString)
in the Network.HTTP.Simple module (doc), which i want to pass around (for mocking later in integration-testing) with my Ctx data-object
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: MonadIO m => Request -> m (Response ByteString)
} deriving (Show)
but I'm getting this error:
Prelude> :l Context.hs
[1 of 1] Compiling Context ( Context.hs, interpreted )
Context.hs:19:32: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Context.hs:19:48: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Failed, no modules loaded.
how is it possible to define this method in my Ctx data-type correctly??
haskell
haskell
asked Nov 19 at 12:51
stefa ng
7416
7416
4
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
1
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01
add a comment |
4
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
1
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01
4
4
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
1
1
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
i don't what the drawbacks are by replacing the constraint MonadIO with the actual Monad IO but for me it was sufficient to get it running:
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)
i dont even get the exact difference between them
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
i don't what the drawbacks are by replacing the constraint MonadIO with the actual Monad IO but for me it was sufficient to get it running:
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)
i dont even get the exact difference between them
add a comment |
up vote
0
down vote
i don't what the drawbacks are by replacing the constraint MonadIO with the actual Monad IO but for me it was sufficient to get it running:
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)
i dont even get the exact difference between them
add a comment |
up vote
0
down vote
up vote
0
down vote
i don't what the drawbacks are by replacing the constraint MonadIO with the actual Monad IO but for me it was sufficient to get it running:
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)
i dont even get the exact difference between them
i don't what the drawbacks are by replacing the constraint MonadIO with the actual Monad IO but for me it was sufficient to get it running:
data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)
i dont even get the exact difference between them
answered Nov 19 at 17:34
stefa ng
7416
7416
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375057%2fhaskell-mocking-define-func-in-datatype-with-class-constraint%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 at 13:32
ok, so you mean: data Ctx m = Ctx { token :: String, httpLBSFunc :: m } ? but then i have to specify the Ctx type everywhere with "Ctx MonadIO (Response ByteString)" ... right? i wouldn't like that. can't i put that "MonadIO (Response ByteString)" constraint somewhere inside the type?
– stefa ng
Nov 19 at 15:35
1
If you want put the constraint in Constructor, considers to use GADTs instead. Or, put constraint on data type like: data MonadIO m => Ctx m = {...} with enable -XDatatypeContexts language extension,it has been deprecated, but you can still use it.
– assembly.jc
Nov 19 at 16:01