[Haskell-cafe] monte carlo trouble
chad.scherrer at gmail.com
Wed Aug 15 18:52:26 EDT 2007
Yeah, I did have troubles with (StateT StdGen Maybe). If it hits a
"Nothing", I'd like it to skip that one and try again with the next
state. But instead, Nothing is treated as a failure condition that
makes the whole thing fail. I just found MaybeT on the wiki, which
looks like it could work. I'll take a look at that and the ListT
I'm starting to think the power of abstraction is a blessing and a
curse. Haskell's abstraction mechanisms are so powerful that it's
generally possible to come up with a way to solve a given problem
elegantly and efficiently. On the other hand, if a problem isn't so
well studied, the bulk of the work is in finding the right
abstraction, which forces generalization beyond what would otherwise
be needed (though it'll be easier the next time!).
On 8/15/07, Paul Johnson <paul at cogito.org.uk> wrote:
> Chad Scherrer wrote:
> > Funny you should say that, I was just experimenting with generating
> > one at a time using (StateT StdGen Maybe). If I get stuck (again) I'll
> > check out ListT. Thanks!
> You definitely want a list not a Maybe. List is for 0 or more results
> whereas Maybe is for 0 or 1. Yes you can have a Maybe [a] with Nothing
> instead of , but its redundant.
> I'm fairly sure you need it the other way out too. All About Monads has
> a demo of StateT s [a] where it is used to solve a logic problem. The
> key point is that in the logic problem each possible result is
> associated with a different state change. However here you want to have
> a list of results and then a state change when you pick one (or a
> subset, or whatever you want). So that would be ListT (StateT StdGen).
"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
More information about the Haskell-Cafe