[Haskell-cafe] Types and hashes of hashes, trouble for a
smithsnorth at gmail.com
Tue Apr 14 06:56:04 EDT 2009
Thanks, I was close, but the I was trying to use (something like) this
statement without the return:
maybe (return Nothing) (flip HashTable.lookup 1000)
More or less like this:
maybe (Nothing) (flip HashTable.lookup 1000)
Which did't work... Guess the return is needed because we use a new
monad (Maybe) inside another monad (IO).
On Mon, Apr 13, 2009 at 7:45 PM, Lennart Augustsson
<lennart at augustsson.net> wrote:
> res <- HashTable.lookup h 3 >>= maybe (return Nothing) (flip
> HashTable.lookup 1000)
> On Mon, Apr 13, 2009 at 6:59 PM, John Smith <smithsnorth at gmail.com> wrote:
>> Yes, agreed. Got any clue on the original problem (except to use Data.Map)?
>> On Mon, Apr 13, 2009 at 6:55 PM, Jason Dagit <dagit at codersbase.com> wrote:
>>> Others have provided help to answer your question but I'd like to
>>> provide a little bit different feedback.
>>> On Mon, Apr 13, 2009 at 8:42 AM, John Smith <smithsnorth at gmail.com> wrote:
>>> > Hi, a java-programmer running into trouble while trying to learn
>>> > Haskell.
>>> > I try to make a hash containing hashes but can not getting a value out
>>> > of
>>> > the innermost hash - I keep running into type-trouble where IO and Maybe
>>> > monad is getting mixed?
>>> > My attempt:
>>> > removeMaybeHash x =
>>> > case x of
>>> > Just ref -> ref
>>> > Nothing -> HashTable.new (==) (\key -> key)
>>> When you see yourself writing a function like this, you could write it
>>> like this instead:
>>> removeMaybeHash (Just ref) = ref
>>> removeMaybeHash Nothing = HashTable.new (==) (\key -> key)
>>> Hopefully you agree this 2 line version is more clear. You could go
>>> further of course and use the function 'maybe' from the prelude, and
>>> pass the function 'id' instead of \key -> key, but I don't want to
>>> overwhelm you.
>>> Good luck,
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe