In Haskell, when using the XStrict language extension, is if short-circuiting?Is there a Haskell compiler or preprocessor that uses strict evaluation?Getting started with HaskellWhat is Haskell used for in the real world?Large-scale design in Haskell?Haskell: How does non-strict and lazy differ?Non-lazy branch of GHCWhat would pattern matching look like in a strict Haskell?Can every functional language be lazy?Call-by-name in Scala vs lazy evaluation in Haskell?How Haskell handles parallel computing on a multicore machine/cluster

Is there a general term for the items in a directory?

How do you say 3 ↑↑↑ 3?

How to trick a fairly simplistic kill-counter?

When did J.K. Rowling decide to make Ron and Hermione a couple?

Went to a big 4 but got fired for underperformance in a year recently - Now every one thinks I'm pro - How to balance expectations?

Being told my "network" isn't PCI Complaint. I don't even have a server! Do I have to comply?

In Haskell, when using the XStrict language extension, is if short-circuiting?

Plotting Chebyshev polynomials using PolarPlot and FilledCurve

Is verification of a blockchain computationally cheaper than recreating it?

A conjectural trigonometric identity

Applied Meditation

Is Norway in the Single Market?

How long should I wait to plug in my refrigerator after unplugging it?

Adding a (stair/baby) gate without facing walls

Does the problem of P vs NP come under the category of Operational Research?

How to draw twisted cuves?

Were there any unmanned expeditions to the moon that returned to Earth prior to Apollo?

Can an alphabet for a Turing machine contain subsets of other alphabets?

Does the use of a new concept require a prior definition?

What is the most 'environmentally friendly' way to learn to fly?

Could flaps be raised upward to serve as spoilers / lift dumpers?

How is Sword Coast North governed?

Ernie and the Superconducting Boxes

Feedback diagram



In Haskell, when using the XStrict language extension, is if short-circuiting?


Is there a Haskell compiler or preprocessor that uses strict evaluation?Getting started with HaskellWhat is Haskell used for in the real world?Large-scale design in Haskell?Haskell: How does non-strict and lazy differ?Non-lazy branch of GHCWhat would pattern matching look like in a strict Haskell?Can every functional language be lazy?Call-by-name in Scala vs lazy evaluation in Haskell?How Haskell handles parallel computing on a multicore machine/cluster






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















Standard Haskell is lazily evaluated, so if myCondition then someValue else doSomeLargeComputation x y z will avoid evaluating doSomeLargeComputation x y z if myCondition is true. My question is, if I enable the language extension XStrict then will doSomeLargeComputation x y z now be evaluated even when myCondition is true?



If so, is there a control flow construct other than explicitly marking doSomeLargeComputation x y z as lazy that can be used to avoid calculating it (like a short-circuiting if statement in a strict language)?










share|improve this question
























  • if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

    – chi
    6 hours ago


















7















Standard Haskell is lazily evaluated, so if myCondition then someValue else doSomeLargeComputation x y z will avoid evaluating doSomeLargeComputation x y z if myCondition is true. My question is, if I enable the language extension XStrict then will doSomeLargeComputation x y z now be evaluated even when myCondition is true?



If so, is there a control flow construct other than explicitly marking doSomeLargeComputation x y z as lazy that can be used to avoid calculating it (like a short-circuiting if statement in a strict language)?










share|improve this question
























  • if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

    – chi
    6 hours ago














7












7








7


1






Standard Haskell is lazily evaluated, so if myCondition then someValue else doSomeLargeComputation x y z will avoid evaluating doSomeLargeComputation x y z if myCondition is true. My question is, if I enable the language extension XStrict then will doSomeLargeComputation x y z now be evaluated even when myCondition is true?



If so, is there a control flow construct other than explicitly marking doSomeLargeComputation x y z as lazy that can be used to avoid calculating it (like a short-circuiting if statement in a strict language)?










share|improve this question














Standard Haskell is lazily evaluated, so if myCondition then someValue else doSomeLargeComputation x y z will avoid evaluating doSomeLargeComputation x y z if myCondition is true. My question is, if I enable the language extension XStrict then will doSomeLargeComputation x y z now be evaluated even when myCondition is true?



If so, is there a control flow construct other than explicitly marking doSomeLargeComputation x y z as lazy that can be used to avoid calculating it (like a short-circuiting if statement in a strict language)?







haskell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 9 hours ago









LogicChainsLogicChains

1,7242 gold badges10 silver badges16 bronze badges




1,7242 gold badges10 silver badges16 bronze badges















  • if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

    – chi
    6 hours ago


















  • if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

    – chi
    6 hours ago

















if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

– chi
6 hours ago






if is non-strict in any language I know -- this is even more important in impure languages, where you do not want to observe the side effects of both branches. In an (insane, IMO) higher-order language with a strict if we could still write (if cond then (_-> doX) else (_-> doY)) () to force it to be lazy, but that hack would need to be used to often that it should be the default.

– chi
6 hours ago













1 Answer
1






active

oldest

votes


















9














No, the branch not taken is not evaluated.



For example:



-# LANGUAGE Strict #-
import Debug.Trace

main :: IO ()
main = print (f (fib 3))

f i =
if i < 5
then trace "then" 0
else trace "else" 1

-- Using fib to avoid inlining or optimization from messing up or test.
fib :: Int -> Int
fib 1 = 1
fib n = n + fib (n-1)


Prints:



*Main> main
else
1


However, if we lift the branches to let bindings then yes, those are strictly evaluated:



f :: Int -> Int
f i =
let f1 = trace "then" 1 in
let f2 = trace "else" 2 in
if i < 5
then f1
else f2


Yields:



% ./LogicChains
then
else
2





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%2f57339988%2fin-haskell-when-using-the-xstrict-language-extension-is-if-short-circuiting%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









    9














    No, the branch not taken is not evaluated.



    For example:



    -# LANGUAGE Strict #-
    import Debug.Trace

    main :: IO ()
    main = print (f (fib 3))

    f i =
    if i < 5
    then trace "then" 0
    else trace "else" 1

    -- Using fib to avoid inlining or optimization from messing up or test.
    fib :: Int -> Int
    fib 1 = 1
    fib n = n + fib (n-1)


    Prints:



    *Main> main
    else
    1


    However, if we lift the branches to let bindings then yes, those are strictly evaluated:



    f :: Int -> Int
    f i =
    let f1 = trace "then" 1 in
    let f2 = trace "else" 2 in
    if i < 5
    then f1
    else f2


    Yields:



    % ./LogicChains
    then
    else
    2





    share|improve this answer





























      9














      No, the branch not taken is not evaluated.



      For example:



      -# LANGUAGE Strict #-
      import Debug.Trace

      main :: IO ()
      main = print (f (fib 3))

      f i =
      if i < 5
      then trace "then" 0
      else trace "else" 1

      -- Using fib to avoid inlining or optimization from messing up or test.
      fib :: Int -> Int
      fib 1 = 1
      fib n = n + fib (n-1)


      Prints:



      *Main> main
      else
      1


      However, if we lift the branches to let bindings then yes, those are strictly evaluated:



      f :: Int -> Int
      f i =
      let f1 = trace "then" 1 in
      let f2 = trace "else" 2 in
      if i < 5
      then f1
      else f2


      Yields:



      % ./LogicChains
      then
      else
      2





      share|improve this answer



























        9












        9








        9







        No, the branch not taken is not evaluated.



        For example:



        -# LANGUAGE Strict #-
        import Debug.Trace

        main :: IO ()
        main = print (f (fib 3))

        f i =
        if i < 5
        then trace "then" 0
        else trace "else" 1

        -- Using fib to avoid inlining or optimization from messing up or test.
        fib :: Int -> Int
        fib 1 = 1
        fib n = n + fib (n-1)


        Prints:



        *Main> main
        else
        1


        However, if we lift the branches to let bindings then yes, those are strictly evaluated:



        f :: Int -> Int
        f i =
        let f1 = trace "then" 1 in
        let f2 = trace "else" 2 in
        if i < 5
        then f1
        else f2


        Yields:



        % ./LogicChains
        then
        else
        2





        share|improve this answer













        No, the branch not taken is not evaluated.



        For example:



        -# LANGUAGE Strict #-
        import Debug.Trace

        main :: IO ()
        main = print (f (fib 3))

        f i =
        if i < 5
        then trace "then" 0
        else trace "else" 1

        -- Using fib to avoid inlining or optimization from messing up or test.
        fib :: Int -> Int
        fib 1 = 1
        fib n = n + fib (n-1)


        Prints:



        *Main> main
        else
        1


        However, if we lift the branches to let bindings then yes, those are strictly evaluated:



        f :: Int -> Int
        f i =
        let f1 = trace "then" 1 in
        let f2 = trace "else" 2 in
        if i < 5
        then f1
        else f2


        Yields:



        % ./LogicChains
        then
        else
        2






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 9 hours ago









        Thomas M. DuBuissonThomas M. DuBuisson

        57.7k7 gold badges91 silver badges155 bronze badges




        57.7k7 gold badges91 silver badges155 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f57339988%2fin-haskell-when-using-the-xstrict-language-extension-is-if-short-circuiting%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

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її