How should the forever function be used?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have a function. Let's say it looks like this:



strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


Then, I want it to run forever, so I do this



strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


But I have an error: variable not in scope: forever. How can I fix it?










share|improve this question




















  • 1





    A side note: forever is not a monad, it is a function.

    – AJFarmar
    Nov 23 '18 at 18:20











  • Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

    – Jorge Adriano
    Nov 23 '18 at 18:59






  • 1





    Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

    – Jorge Adriano
    Nov 23 '18 at 19:02


















2















I have a function. Let's say it looks like this:



strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


Then, I want it to run forever, so I do this



strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


But I have an error: variable not in scope: forever. How can I fix it?










share|improve this question




















  • 1





    A side note: forever is not a monad, it is a function.

    – AJFarmar
    Nov 23 '18 at 18:20











  • Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

    – Jorge Adriano
    Nov 23 '18 at 18:59






  • 1





    Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

    – Jorge Adriano
    Nov 23 '18 at 19:02














2












2








2








I have a function. Let's say it looks like this:



strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


Then, I want it to run forever, so I do this



strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


But I have an error: variable not in scope: forever. How can I fix it?










share|improve this question
















I have a function. Let's say it looks like this:



strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


Then, I want it to run forever, so I do this



strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code


But I have an error: variable not in scope: forever. How can I fix it?







haskell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 19:11









AJFarmar

9,34722954




9,34722954










asked Nov 23 '18 at 18:13









Kada FuiteKada Fuite

163




163








  • 1





    A side note: forever is not a monad, it is a function.

    – AJFarmar
    Nov 23 '18 at 18:20











  • Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

    – Jorge Adriano
    Nov 23 '18 at 18:59






  • 1





    Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

    – Jorge Adriano
    Nov 23 '18 at 19:02














  • 1





    A side note: forever is not a monad, it is a function.

    – AJFarmar
    Nov 23 '18 at 18:20











  • Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

    – Jorge Adriano
    Nov 23 '18 at 18:59






  • 1





    Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

    – Jorge Adriano
    Nov 23 '18 at 19:02








1




1





A side note: forever is not a monad, it is a function.

– AJFarmar
Nov 23 '18 at 18:20





A side note: forever is not a monad, it is a function.

– AJFarmar
Nov 23 '18 at 18:20













Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

– Jorge Adriano
Nov 23 '18 at 18:59





Your example has no variables, so we don't know why there's a variable out of scope. That just means you're referring to some variable that is unknown (in that context).

– Jorge Adriano
Nov 23 '18 at 18:59




1




1





Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

– Jorge Adriano
Nov 23 '18 at 19:02





Also while you can use forever, if running something forever is confusing you this much, maybe you should be trying to do it without resorting to forever first, for instructional purposes. All you need is to code an "infinite loop", i.e. write a function that "runs the code" then calls itself.

– Jorge Adriano
Nov 23 '18 at 19:02












1 Answer
1






active

oldest

votes


















8














You must import forever from Control.Monad. Add this to the top of your file:



import Control.Monad (forever)


When the compiler says variable not in scope..., it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.



How did I know this? If you search for forever on Hoogle, it says that it is in the Control.Monad module, in the base package. Hence, you must import it in order to use it.






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%2f53451323%2fhow-should-the-forever-function-be-used%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









    8














    You must import forever from Control.Monad. Add this to the top of your file:



    import Control.Monad (forever)


    When the compiler says variable not in scope..., it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.



    How did I know this? If you search for forever on Hoogle, it says that it is in the Control.Monad module, in the base package. Hence, you must import it in order to use it.






    share|improve this answer




























      8














      You must import forever from Control.Monad. Add this to the top of your file:



      import Control.Monad (forever)


      When the compiler says variable not in scope..., it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.



      How did I know this? If you search for forever on Hoogle, it says that it is in the Control.Monad module, in the base package. Hence, you must import it in order to use it.






      share|improve this answer


























        8












        8








        8







        You must import forever from Control.Monad. Add this to the top of your file:



        import Control.Monad (forever)


        When the compiler says variable not in scope..., it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.



        How did I know this? If you search for forever on Hoogle, it says that it is in the Control.Monad module, in the base package. Hence, you must import it in order to use it.






        share|improve this answer













        You must import forever from Control.Monad. Add this to the top of your file:



        import Control.Monad (forever)


        When the compiler says variable not in scope..., it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.



        How did I know this? If you search for forever on Hoogle, it says that it is in the Control.Monad module, in the base package. Hence, you must import it in order to use it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 18:16









        AJFarmarAJFarmar

        9,34722954




        9,34722954
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451323%2fhow-should-the-forever-function-be-used%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy