[Haskell-cafe] Markov Text Generator & Randomness

Charles-Pierre Astolfi cpa at crans.org
Thu Jul 24 21:35:59 UTC 2014


You're right Ben, changing the signature to Word instead of RVar Word
did the trick. Stupid mistake.

Thanks!
-- 
Cp


On Thu, Jul 24, 2014 at 9:55 AM, Ben Gamari <ben at smart-cactus.org> wrote:
> Charles-Pierre Astolfi <cpa at crans.org> writes:
>
>>>     "The old man looked from his glass across the square, then over at the waiters."
>> You're embarrassingly right! But then, "those the" definitely never
>> appears, altough it does in my generated text.
>>
>>> Otherwise my cursory look turned up no bugs.
>> Unfortunately there is :(
>>
>
> Ahh yes, looking a bit more closely now I have a few points:
>
>   1. In `draw`: The first argument is an action which will return a new
>      word. Instead of passing `rword :: RVar Word`, you presumably rather want to
>      pass `word :: Word`. This is likely the cause of your bug.
>
>   2. In `draw`: Instead of `weightedSample` which produces a random shuffling of
>      the entire list,  you really just want to draw a single word. This
>      is a categorical distribution; use `Data.Random.Categorical.fromList`
>      to construct the distribution and `R.rvar` to draw a variate. Note
>      that you may only want to avoid doing the former more than once as
>      construction of the distribution requires sorting and normalizing.
>
>   3. `map (\(x,y)->(y,x))` is just `map swap` where `swap` is provided
>      by `Data.Tuple`.
>
> My quick rework of your code can be found here [1].
>
> Cheers,
>
> - Ben
>
>
> [1] http://lpaste.net/108025


More information about the Haskell-Cafe mailing list