That works, but I don't understand how I can print the map mp on one line but then when I try to extract a value out of it it's no longer a map but a triple. How can mp be a map on one line but not on another? Michael ============= [1 of 1] Compiling Main ( markov4.hs, markov4.o )Linking markov4 ...[michael@hostname ~]$ echo "I am lost." | ./markov4(fromList [(("\n","\n"),["I"]),(("\n","I"),["am"]),(("I","am"),["lost."])],("am","lost."),[])["I"][michael@hostname ~]$ ghciGHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for helpLoading package ghc-prim ... linking ... done.Loading package integer-gmp ... linking ... done.Loading package base ... linking ... done.Loading package ffi-1.0 ... linking ... done.Prelude> :m + Data.MapPrelude Data.Map> let mp = fromList [(1,'a'),(2,'b'),(3,'c')]Loading package array-0.3.0.1 ... linking ... done.Loading package containers-0.3.0.0 ... linking ... done.Prelude Data.Map> :t mpmp :: Map Integer CharPrelude Data.Map> mpfromList [(1,'a'),(2,'b'),(3,'c')]Prelude Data.Map> mp ! 2'b'Prelude Data.Map> --- On Fri, 5/20/11, Arlen Cuss <celtic@sairyx.org> wrote: From: Arlen Cuss <celtic@sairyx.org> Subject: Re: [Haskell-cafe] Can't access map value with key. To: "michael rice" <nowgate@yahoo.com> Cc: haskell-cafe@haskell.org Date: Friday, May 20, 2011, 11:36 PM On Fri, 2011-05-20 at 19:04 -0700, michael rice wrote:
markov4.hs:35:27: Couldn't match expected type `Map k a' against inferred type `(Map Prefix [String], Prefix, [String])'
ghc seems to believe `mp' here is not just a map, but the entire state (which is what execState is meant to give you).
type GeneratorState = State ((Map Prefix [String]),Prefix,[String])
The state is a triple, so you need to match to get the real map out:
let (themap,_,_) = mp putStrLn $ show $ themap ! (non_word,non_word)