[Haskell-cafe] Is it usual to read a Maybe (IORef a) ?

minh thu noteed at gmail.com
Thu Sep 4 13:50:20 EDT 2008

2008/9/4 Paul Johnson <paul at cogito.org.uk>:
> minh thu wrote:
>> Do you suggest I use
>> data Thing = Thing | None
>> and IORef Thing instead of
>> data Thing = Thing
>> and Maybe (IORef Thing) ?
>> I'm writing a data structure that can hold  Things (and that can be
>> mutated) or
>> nothing (there is a hole in the wrapping data).
> I'd have thought you wanted "IORef (Maybe Thing)", which says that the
> pointer always exists, but may not point to anything.  On the other hand
> "Maybe (IORef Thing)" says that the pointer may or may not exist.

Yes, someone else said it too. But you saiy that regarding the pointer. If you
look at the thing the pointer (if any) points at, what's the difference ?
Either there is none : Nothing or IORef Nothing, or there is one :
Just (IORef 5)
or IORef (Just 5).

The difference is you have to allocate a new IORef whenever you want to make
the thing pointed at appear in the first case.

I'm more concerned by the hole the user can create/fill than by emulating C null

Anyway, as Lennart suggested, I will try with Data.Map or Data.IntMap.


More information about the Haskell-Cafe mailing list