<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Gregory,<br>
<br>
I was wondering about that, because of the following:<br>
<br>
[1 of 1] Compiling Main ( hash1.hs, interpreted )<br>
Ok, modules loaded: Main.<br>
*Main> ht <- new (==) dummy :: IO MyHashTable<br>
*Main> dummy "mike"<br>
7<br>
*Main> dummy "michael"<br>
7<br>
*Main> insert ht "mike" 1<br>
*Main> toList ht<br>
[("mike",1)]<br>
*Main> insert ht "michael" 2<br>
*Main> toList ht<br>
[("michael",2),("mike",1)]<br>
*Main> insert ht "miguel" 3<br>
*Main> toList ht<br>
[("miguel",3),("michael",2),("mike",1)]<br>
*Main> :t dummy "miguel"<br>
dummy "miguel" :: Int32<br>
*Main> <br>
<br>
It seems my dummy function is being ignored. I figured I would only be able to store a single value with a hash function that always returns 7. Why ask for a hash function and not use it?<br>
<br>
Also, it's said that it is good programming practice to include type
information in function definitions, so I always try to do that, even
though it usually leads to my code being rejected. I need to step back
and use the :t and module functions defs to figure out what types are
returned and required as arguments, instead of trying to puzzle it out
myself.<br><br>Like juggling, there's a lot of balls in the air w/Haskell, lots of things to remember, but it's the most intriguing computer language I've looked at in a long time.<br>
<br>
Thanks for your input.<br>
<br>
Michael<br>
<br>
<br><br>--- On <b>Tue, 11/17/09, Gregory Crosswhite <i><gcross@phys.washington.edu></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Gregory Crosswhite <gcross@phys.washington.edu><br>Subject: Re: [Haskell-cafe] Simple hash table creation<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: haskell-cafe@haskell.org, "Daniel Fischer" <daniel.is.fischer@web.de><br>Date: Tuesday, November 17, 2009, 3:30 PM<br><br><div id="yiv1217988089"><div>Look in Data.Int for a list of the Int types.</div><div><br></div><div>Basically you generally only use Int unless you are working at a lower-level which has an explicit requirement for the number of bits. In this case, HashTable has such a requirement, so you have two choices: you can either change the type annotation on dummy:</div><div><br></div><div><br></div><div>import
Data.Int</div><div><br></div><div>dummy:: String -> Int32<br>dummy s = 7</div><div><br></div><div><br></div><div><br></div><div>or you can just leave it off entirely, and GHC will automatically infer the correct type (without you needing to import Data.Int):</div><div><br></div><div>dummy s = 7</div><div><br></div><br><div><div>On Nov 17, 2009, at 12:09 PM, michael rice wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Hi Daniel,<br>
<br>
Thanks for the IO monad reminder.<br>
<br>
What is GHC.Int.Int32? Can't find it on Hoogle.<br>
<br>
Michael<br>
<br>
==================<br>
<br>
*Main> ht <- new (==) dummy :: IO MyHashTable<br>
<br>
<interactive>:1:15:<br>
Couldn't match expected type `GHC.Int.Int32'<br>
against inferred type `Int'<br>
In the second argument of `new', namely `dummy'<br>
In a stmt of a 'do' expression:<br>
ht <- new (==) dummy :: IO MyHashTable<br>
*Main> :t dummy<br>
dummy :: String -> Int<br>
*Main> <br>
<br><br><br>--- On <b>Tue, 11/17/09, Daniel Fischer <i><<a rel="nofollow" ymailto="mailto:daniel.is.fischer@web.de" target="_blank" href="/mc/compose?to=daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Fischer <<a rel="nofollow" ymailto="mailto:daniel.is.fischer@web.de" target="_blank" href="/mc/compose?to=daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>><br>Subject: Re: [Haskell-cafe] Simple hash table creation<br>To: <a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>Date: Tuesday, November 17, 2009, 2:45 PM<br><br><div class="plainMail">Am Dienstag 17 November 2009 20:36:46 schrieb Daniel Fischer:<br>> What you probably wanted was<br>><br>> type MyHashTable = HashTable String Int --
not data MyHashTable<br>><br><br>Just in case it's not clear:<br><br>> ht <- new (==) dummy :: IO MyHashTable<br><br>only works at the prompt or in an IO do-block, not at the top level of the module.<br><br>><br>> then ht is a hashtable of type MyHashTable.<br><br><br>_______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow">Haskell-Cafe@haskell.org</a><br><a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></blockquote></td></tr></tbody></table><br>
_______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></div></blockquote></td></tr></table><br>