4 ms·
Not a dumb question at all! You can create cycles in Haskell thanks to lazy evaluation. I can make a circular list in Haskell with the following: x :: [Int] x
by openasocket 10y ago
Not a dumb question at all! You can create cycles in Haskell thanks to lazy evaluation. I can make a circular list in Haskell with the following:
x :: [Int]
x = 0 : y
y :: [Int]
y = 1 : x
And thus we have a circular list with the elements 0 and 1. It's technically an infinite-length list with 0 and 1 repeating forever, but Haskell will represent this in memory as a circular list.
- OskarS 10y agoAh, I see, I figured that there might be some case like that. I would have expected that to be a compile-time error because `y` is an unrecognized identifier by the time `x` is defined, but I guess it makes sense with lazy evaluation to not make that kind of ordering matter.
- hood_syntax 10y agoYeah, all definitions are module level unless they are scoped in let or where blocks (someone correct me if I'm mistaken)
- tener 10y agoLazy evaluation is not important item here. It is merely the semantics is defined in a way that the order of declarations does not matter. Other languages have this property too - say, C# (not entirely true, but pretty close - at least if you think about top level methods etc.). Also an example where the order of declarations does not matter at all, because there is just one declaration: x :: [Integer] x = 0 : 1 : x