Based on Haskell, I read the story of Idris regarding laziness (laxity). I looked through the latest release notes and found code similar to the following
myIf : (b : Bool) -> (t : Lazy a) -> (e : Lazy a) -> a myIf True te = t myIf False te = e
I wrote a simple factorial function to test it
myFact : Int -> Int myFact n = myIf (n == 1) 1 (n * myFact (n-1))
I ran and it worked!
> myFact 5 120 : Int
I decided to break it by changing the signature like myIf to
myIf : (b : Bool) -> a -> a -> a
I reloaded idris repl and ran myFact 5 , expecting infinite recursion. To my surprise, it worked the same way anyway!
Can idris find out when strictness should be avoided? Why is this not repeated forever?
I use Idris 0.9.15 and not one of the release notes between them and the related notes mentions any changes.
lazy-evaluation idris
mjgpy3
source share