<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>You don't need to create a new type for a String -&gt; Int hashtable, you already get it for free because HashTable is a parameterized type.</div><div><br></div><div>Also, although you are apparently trying to make life simpler for yourself using a HashTable, you are actually making like more complicated because the Data.HashTable implementation can only be worked with inside the IO monad. &nbsp;So what you'd need is something like:</div><div><br></div><div><br></div><div>====================</div><div><br></div><div><div><div>import Prelude hiding (lookup)</div><div>import Data.HashTable</div><div><br></div><div>dummy s = 7</div><div><br></div><div>main = do</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ht &lt;- new (==) dummy</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>insert ht "Foo" 12</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;value &lt;- lookup ht "Foo"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;putStrLn . show $ value</div><div><br></div></div></div><div>====================</div><div><br></div><div>Note that I didn't have to label any of the types; &nbsp;Haskell is smart enough to mostly infer all of them automatically. &nbsp;The main reason to include types is if there is some ambiguity. &nbsp;So for example, if you actually wanted to map Strings to Floats, then you would need to explicitly tell it somewhere that the values it is storing are floats. &nbsp;You could do this by either pinning down explicitly the HashTable type:</div><div><br></div><div><div>====================</div><div><br></div><div><div><div>import Prelude hiding (lookup)</div><div>import Data.HashTable</div><div><br></div><div>dummy s = 7</div><div><br></div><div>main = do</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>ht &lt;- new (==) dummy &nbsp;:: IO (HashTable String Float)</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>insert ht "Foo" 12</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;value &lt;- lookup ht "Foo"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;putStrLn . show $ value</div><div><br></div></div></div><div>====================</div><div><br></div><div>Or just by pinning down the type of a value that you insert into it:</div><div><br></div><div><div>====================</div><div><br></div><div><div><div>import Prelude hiding (lookup)</div><div>import Data.HashTable</div><div><br></div><div>dummy s = 7</div><div><br></div><div>main = do</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>ht &lt;- new (==) dummy</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>insert ht "Foo" (12 :: Float)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;value &lt;- lookup ht "Foo"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;putStrLn . show $ value</div><div><br></div></div></div><div>====================</div><div><br></div><div>Again, the downside though is that you can't work with HashTable outside of the IO monad. &nbsp;If what you want is just a map from strings to values, then you probably are better off using Data.Map:</div><div><br></div><div><div>====================</div><div><br></div><div><div><div><div>import Prelude hiding (lookup)</div><div>import Data.Map</div><div><br></div><div>my_map = empty :: Map String Int</div><div><br></div><div>my_map_after_adding_key = insert "Foo" 12 my_map</div><div><br></div><div>value_associated_with_Foo = lookup "Foo" my_map_after_adding_key</div><div><br></div><div>main = putStrLn . show $ value_associated_with_Foo</div></div><div><br></div></div></div><div>====================</div></div><div><br></div><div>Cheers,</div><div>Greg</div></div></div><br><div><div>On Nov 17, 2009, at 11:16 AM, michael rice wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font: inherit;">I'm trying to create a hash table. Yeah, I know, don't use hash tables, but I need to create something I'm familiar with, not something I've never worked with before. What's wrong with this code?<br><br>Michael<br><br>====================<br><br>import Prelude hiding (lookup)<br>import Data.HashTable<br><br>data MyHashTable = HashTable String Int<br><br>dummy:: String -&gt; Int<br>dummy s = 7<br><br>ht = MyHashTable.new (==) dummy<br><br>====================<br><br>[michael@localhost ~]$ ghci hash1<br>GHCi, version 6.10.3: <a href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a>&nbsp; :? for help<br>Loading package ghc-prim ... linking ... done.<br>Loading package integer ... linking ... done.<br>Loading package base ... linking ... done.<br>[1 of 1] Compiling Main&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( hash1.hs, interpreted )<br><br>hash1.hs:9:5: Not in
 scope: `MyHashTable.new'<br>Failed, modules loaded: none.<br>Prelude&gt; <br><br></td></tr></tbody></table><br>



      _______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></body></html>