2008/9/4 Paul Johnson <[EMAIL PROTECTED]>: > 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 pointers. Anyway, as Lennart suggested, I will try with Data.Map or Data.IntMap. Thanks thu _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe