turn off lazy evaluation in haskell

前端 未结 7 2026
长发绾君心
长发绾君心 2020-12-14 19:03

Is it possible to turn off lazy evaluation in Haskell?

Is there a specific compiler flag of library to facilitate this?

I wanted to try something new with

相关标签:
7条回答
  • 2020-12-14 19:29

    The strict-identity package has a strict version of the Identity monad.

    You can find it here: https://hackage.haskell.org/package/strict-identity

    The usage would look something like this:

    foo = runStrictIdentity $! do
        x <- f a b
        y <- g x y
        return $! x + y
    

    Each time return or bind >>= is used, the two parts are evaluated using seq, giving a reasonable guarantee of strictness provided your data structure isn't too deep. This works, for i.e. numbers and basic structures.

    0 讨论(0)
提交回复
热议问题