On Sep 4, 2008, at 13:41 , Andrew Coppin wrote:
Ryan Ingram wrote:
It's pretty simple, I think.

type ExpGen = ReaderT [String] Gen

arbExp :: ExpGen Expression
-- exercise for the reader

instance Arbitrary Expression where
   arbitrary = runReaderT arbExp []
   coarbitrary = coarbExp

coarbExp (Var s)      = variant 0 . coarbitrary s
coarbExp (Apply a b)  = variant 1 . coarbitrary a . coarbitrary b
coarbExp (Lambda s e) = variant 2 . coarbitrary s . coarbitrary e

instance Arbitrary Char where
 arbitrary   = elements "abcdefghijklmnopqrstuvwxyz_"
 coarbitrary = coarbitrary . fromEnum


o_O

I love the way other people have wildly different ideas of "simple" than me. I'm staring at this and completely failing to comprehend it. (But then, anything with "co" in the name generally makes little sense to me...) Why on earth would you need a reader monad? Surely if you want to add bound variables and then later query what variables are bound, you'd want a state monad? Hmm, I'm completely lost here.

Reader, in this case, is a State monad with the addition of scopes: to create a new nested scope r' given a scope r, "let r' = local r". The [String] is a list of variable names, if this is doing what I think it is.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to