haskell mocking: define func in datatype with class-constraint












2














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??










share|improve this question


















  • 4




    Ctx need parameter like: data Ctx m = Ctx {...}
    – assembly.jc
    Nov 19 '18 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 '18 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 '18 at 16:01


















2














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??










share|improve this question


















  • 4




    Ctx need parameter like: data Ctx m = Ctx {...}
    – assembly.jc
    Nov 19 '18 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 '18 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 '18 at 16:01
















2












2








2







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??










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 12:51









stefa ng

7416




7416








  • 4




    Ctx need parameter like: data Ctx m = Ctx {...}
    – assembly.jc
    Nov 19 '18 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 '18 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 '18 at 16:01
















  • 4




    Ctx need parameter like: data Ctx m = Ctx {...}
    – assembly.jc
    Nov 19 '18 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 '18 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 '18 at 16:01










4




4




Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 '18 at 13:32




Ctx need parameter like: data Ctx m = Ctx {...}
– assembly.jc
Nov 19 '18 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 '18 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 '18 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 '18 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 '18 at 16:01














1 Answer
1






active

oldest

votes


















0














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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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






    share|improve this answer


























      0














      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






      share|improve this answer
























        0












        0








        0






        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 17:34









        stefa ng

        7416




        7416






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith