<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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( hash1.hs, interpreted )<br>
Ok, modules loaded: Main.<br>
*Main&gt; ht &lt;- new (==) dummy :: IO MyHashTable<br>
*Main&gt; dummy "mike"<br>
7<br>
*Main&gt; dummy "michael"<br>
7<br>
*Main&gt; insert ht "mike" 1<br>
*Main&gt; toList ht<br>
[("mike",1)]<br>
*Main&gt; insert ht "michael" 2<br>
*Main&gt; toList ht<br>
[("michael",2),("mike",1)]<br>
*Main&gt; insert ht "miguel" 3<br>
*Main&gt; toList ht<br>
[("miguel",3),("michael",2),("mike",1)]<br>
*Main&gt; :t dummy "miguel"<br>
dummy "miguel" :: Int32<br>
*Main&gt; <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&nbsp; 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&nbsp; 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>&lt;gcross@phys.washington.edu&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Gregory Crosswhite &lt;gcross@phys.washington.edu&gt;<br>Subject: Re: [Haskell-cafe] Simple hash table creation<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: haskell-cafe@haskell.org, "Daniel Fischer" &lt;daniel.is.fischer@web.de&gt;<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. &nbsp;In this case, HashTable has such a requirement, so you have two choices: &nbsp;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 -&gt; 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&gt; ht &lt;- new (==) dummy :: IO MyHashTable<br>
<br>
&lt;interactive&gt;:1:15:<br>
&nbsp;&nbsp;&nbsp; Couldn't match expected type `GHC.Int.Int32'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; against inferred type `Int'<br>
&nbsp;&nbsp;&nbsp; In the second argument of `new', namely `dummy'<br>
&nbsp;&nbsp;&nbsp; In a stmt of a 'do' expression:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ht &lt;- new (==) dummy :: IO MyHashTable<br>
*Main&gt; :t dummy<br>
dummy :: String -&gt; Int<br>
*Main&gt; <br>
<br><br><br>--- On <b>Tue, 11/17/09, Daniel Fischer <i>&lt;<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>&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Fischer &lt;<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>&gt;<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>&gt; What you probably wanted was<br>&gt;<br>&gt; type MyHashTable = HashTable String Int --
 not data MyHashTable<br>&gt;<br><br>Just in case it's not clear:<br><br>&gt; ht &lt;- 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>&gt;<br>&gt; 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>