[Haskell-cafe] Markov chain algorithm (from "The Practice of Programming", Kernighan/Pike)

Eugene Kirpichov ekirpichov at gmail.com
Wed May 11 17:48:21 CEST 2011


Because insertWith has a different type than your code needs.
It's not like a -> b -> b, it's a -> a -> a and (:) is not like this.
Try insertWith (++ or flip (++)) [("Moby", "Dick")] ....

2011/5/11 michael rice <nowgate at yahoo.com>

> It's hard to improve on a 20 line Awk program for generating text but I
> thought it would be fun to investigate a Haskell solution.
>
> Why can't I cons an element onto an existing list?
>
> Michael
>
> Prelude Data.List Data.Map> insertWith (:) ("Moby", "Dick") "will"
> (fromList [(("Joe", "Blow"),["is"]), (("Moby", "Dick"),["may"])])
>
> <interactive>:1:11:
>     Occurs check: cannot construct the infinite type: a = [a]
>       Expected type: a
>       Inferred type: [a]
>     In the first argument of `insertWith', namely `(:)'
>     In the expression:
>         insertWith
>           (:)
>           ("Moby", "Dick")
>           "will"
>           (fromList [(("Joe", "Blow"), ["is"]), (("Moby", "Dick"),
> ["may"])])
> Prelude Data.List Data.Map>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110511/d88ea8ea/attachment.htm>


More information about the Haskell-Cafe mailing list