Does Haskell support the concept of unbound variables as in the Oz programming language?
Haskell only supports variables in terms of values in (monadic) contexts. Once you look at those, there are certain ones like MVar which can indeed be empty.
If you want to represent simple nullability of a value, though, Maybe a is a perfect way to do that, separate from the actual value being a reference to something mutable or just an immutable something.
To expand and illustrate:
newIORef :: a -> IO (IORef a)
But we can easily write newEmptyIORef as such:
newEmptyIORef :: IO (IORef (Maybe a))
newEmptyIORef = newIORef Nothing
Take note that Maybe (IORef a) ≠ IORef (Maybe a).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With