Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Haskell support unbound variables?

Tags:

haskell

oz

Does Haskell support the concept of unbound variables as in the Oz programming language?

like image 673
Derek Mahar Avatar asked Aug 28 '26 21:08

Derek Mahar


1 Answers

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).

like image 146
Bartek Banachewicz Avatar answered Aug 30 '26 12:08

Bartek Banachewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!