[Haskell-cafe] Reader monad, refactoring and missing the point all at once

2012-05-01 Thread Eugene Dzhurinsky
Hi all! Last day I was trying to fix idiii library, because it uses utf8 for parsing non-unicode content. I found the functions > -- | Parses one value and returns it as a 'String' > parseString :: CharEncoding -> TagParser String > parseString enc = do > v <- case enc of > 0x01 -> pars

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread michael rice
And swap the arguments. Thanks for going the extra mile. Michael --- On Thu, 2/3/11, Daniel Fischer wrote: From: Daniel Fischer Subject: Re: [Haskell-cafe] Reader monad wrapping State monad To: "michael rice" Cc: haskell-cafe@haskell.org Date: Thursday, February 3, 2011, 4

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread Daniel Fischer
On Thursday 03 February 2011 21:40:13, michael rice wrote: > Hi Daniel, > > Ok, but what I was looking for was ReaderT on top, State on the bottom. No problem, just change the definition of the Heron type synonym and swap the applcations of runReader[T] and evalState[T] in mySqrt, the monadic sq

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread michael rice
this case no use of lift at all. Michael --- On Thu, 2/3/11, Daniel Fischer wrote: From: Daniel Fischer Subject: Re: [Haskell-cafe] Reader monad wrapping State monad To: haskell-cafe@haskell.org Cc: "michael rice" Date: Thursday, February 3, 2011, 2:54 PM On Thursday 03 Februar

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread Ozgur Akgun
On 3 February 2011 19:18, michael rice wrote: > but how do I get the constant a from the Reader monad? > http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-Reader.html#v:ask You also need to change the type to use ReaderT. -- Ozgur Akgun _

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread Daniel Fischer
On Thursday 03 February 2011 20:18:43, michael rice wrote: > Given the first program, it seems that the unchanging first element of > the tuple could be handled by a Reader monad, leading to the second > program, where b becomes the state, but how do I get the constant a from > the Reader monad? Y

Re: [Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread Thomas Davie
Is the idea here merely an exercise in using the state monad? This can be easily performed using pure code. Bob On 3 Feb 2011, at 19:18, michael rice wrote: > Given the first program, it seems that the unchanging first element of the > tuple could be handled by a Reader monad, leading to the

[Haskell-cafe] Reader monad wrapping State monad

2011-02-03 Thread michael rice
Given the first program, it seems that the unchanging first element of the tuple could be handled by a Reader monad, leading to the second program, where b becomes the state, but how do I get the constant a from the Reader monad? Michael == import Control.Monad.State type Gen

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Michael Lazarev
2010/12/30 David Leimbach : > > Reader Writer State is commonly needed in big applications so transformers > provides one for us: > http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-Trans-RWS-Lazy.html > Pretty cool stuff if you ask me.  I often wondered about

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread David Leimbach
On Wed, Dec 29, 2010 at 1:48 PM, Michael Lazarev wrote: > 2010/12/29 michael rice > > I had an "Aha!" moment and it all makes sense now. Just as the State > monad can hold a generator (which can change) and pass it down a calculation > chain, a Reader monad can hold an environment (which doesn't

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Michael Lazarev
2010/12/29 michael rice > I had an "Aha!" moment and it all makes sense now. Just as the State monad > can hold a generator (which can change) and pass it down a calculation chain, > a Reader monad can hold an environment (which doesn't change) and pass it > down a calculation chain. I was wond

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Michael Lazarev
2010/12/29 Albert Y. C. Lai > On 10-12-29 12:50 PM, michael rice wrote: > >> I think of (r -> m a) as a type signature and Int or Bool by themselves >> as types. So, all type signatures are themselves types? >> > > http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-620004 > > In

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Albert Y. C. Lai
On 10-12-29 12:50 PM, michael rice wrote: I think of (r -> m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-620004 In particular gendecl → vars :: [context =>] typ

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread michael rice
9/10, Daniel Fischer wrote: From: Daniel Fischer Subject: Re: [Haskell-cafe] Reader monad To: haskell-cafe@haskell.org Cc: "michael rice" Date: Wednesday, December 29, 2010, 2:47 PM On Wednesday 29 December 2010 19:30:11, michael rice wrote: > Yes, I'd already noticed that ReaderT

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Daniel Fischer
On Wednesday 29 December 2010 19:30:11, michael rice wrote: > Yes, I'd already noticed that ReaderT preceded Reader. Guess I'll have > to check out the Indentity monad too. I hope it's not dependent upon yet > another monad.  No, the Identity monad stands alone. And as the name suggests, it's pret

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread michael rice
Michael Lazarev Subject: Re: [Haskell-cafe] Reader monad To: "michael rice" Cc: haskell-cafe@haskell.org Date: Wednesday, December 29, 2010, 12:42 PM 2010/12/29 michael rice > > From the docs (and tuts) newtype creates a new type out of an existing type > and gives

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Tillmann Rendel
Hi, Michael Rice wrote: I think of (r -> m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? Yes. In Haskell, functions are first class, so function types like (r -> m a) are themselves types. Tillmann __

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread michael rice
I think of (r -> m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? Michael --- On Wed, 12/29/10, Henning Thielemann wrote: From: Henning Thielemann Subject: Re: [Haskell-cafe] Reader monad To: "michael rice" Cc:

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Michael Lazarev
2010/12/29 michael rice > > From the docs (and tuts) newtype creates a new type out of an existing type > and gives a single constructor for doing so. > > what is the existing type? Michael, you may want to see this section: http://learnyouahaskell.com/functors-applicative-functors-and-monoids#t

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Henning Thielemann
On Wed, 29 Dec 2010, michael rice wrote: In the case of ReaderT and StateT newtype ReaderT r m a = ReaderT {     -- | The underlying computation, as a function of the environment.     runReaderT :: r -> m a     } newtype StateT s m a = StateT { runStateT :: s -> m (a, s) } what is th

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread michael rice
? Michael --- On Wed, 12/29/10, Ryan Ingram wrote: From: Ryan Ingram Subject: Re: [Haskell-cafe] Reader monad To: "michael rice" Cc: haskell-cafe@haskell.org Date: Wednesday, December 29, 2010, 11:11 AM On Wed, Dec 29, 2010 at 8:06 AM, michael rice wrote: > Is there an unpara

Re: [Haskell-cafe] Reader monad

2010-12-29 Thread Ryan Ingram
On Wed, Dec 29, 2010 at 8:06 AM, michael rice wrote: > Is there an unparameterizable reader monad? I'm not sure this is the answer you are looking for, but it seems like the obvious one. Pick an "r", say "String". Now "Reader String" is an unparameterizable reader monad that passes around a St

[Haskell-cafe] Reader monad

2010-12-29 Thread michael rice
From: Control.Monad.Reader type Reader r = ReaderT r IdentityThe parameterizable reader monad. Computations are functions of a shared environment. The return function ignores the environment, while >>= passes the inherited environment to both subcomputations Is there an unparameteri

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-24 Thread Henning Thielemann
On Fri, 22 Aug 2008, Alexander Dunlap wrote: You can always change how you unsafePerformIO the data, though. If you want to set Planck's constant to 42 (or whatever), just change the unsafePerformIO $ to unsafePerformIO $ return 42. you can't change it at runtime ___

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-22 Thread Alexander Dunlap
On Wed, Aug 20, 2008 at 1:49 AM, Henning Thielemann <[EMAIL PROTECTED]> wrote: > > On Mon, 18 Aug 2008, [EMAIL PROTECTED] wrote: > >> G'day all. >> >> Quoting Bjorn Buckwalter <[EMAIL PROTECTED]>: >> >>> I'd store the constants in a data structure along the lines of: >>> data AstroData a = Ast

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-20 Thread Henning Thielemann
On Mon, 18 Aug 2008, [EMAIL PROTECTED] wrote: G'day all. Quoting Bjorn Buckwalter <[EMAIL PROTECTED]>: I'd store the constants in a data structure along the lines of: data AstroData a = AstroData { mu_Earth:: GravitationalParameter a , leapSeconds :: LeapSecondTable } I would like

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread ajb
G'day all. Quoting "Richard A. O'Keefe" <[EMAIL PROTECTED]>: Just an idiot-level question: so these "constants" are subject to revision, but *how often*? Good question. For leap seconds: - The data can change no quicker than once every 6 months. - The shortest time between changes was 6 m

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Richard A. O'Keefe
Just an idiot-level question: so these "constants" are subject to revision, but *how often*? What is the actual cost of recompiling and using them *as* constants, compared with the cost of rereading the stuff every time you run the program and passing it around? -- If stupidity were a crime, who

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread ajb
G'day all. Quoting Bjorn Buckwalter <[EMAIL PROTECTED]>: I'd store the constants in a data structure along the lines of: data AstroData a = AstroData { mu_Earth:: GravitationalParameter a , leapSeconds :: LeapSecondTable } I would like to know if there is any consensus on what is

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Brandon S. Allbery KF8NH
On 2008 Aug 18, at 17:09, Evan Laforge wrote: They also seem to be removed from ghc: http://www.haskell.org/pipermail/cvs-ghc/2006-September/031824.html Again, that's *linear* implicit parameters (%foo instead of ?foo). Oh, you're right. I made exactly the same mistake you made, and righ

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Evan Laforge
>> They also seem to be removed from ghc: >> >> http://www.haskell.org/pipermail/cvs-ghc/2006-September/031824.html > > > Again, that's *linear* implicit parameters (%foo instead of ?foo). Oh, you're right. I made exactly the same mistake you made, and right after you warned against making it too

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Brandon S. Allbery KF8NH
On 2008 Aug 18, at 16:20, Evan Laforge wrote: Which is comparable to the Reader version (with the advantage/disadvantage of the body of 'escapeVelocity' not being monadic). In my opinion the implicit parameters don't make things simpler, only less portable, that's why I prefer the Reader mon

Re: Fwd: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Evan Laforge
>> Which is comparable to the Reader version (with the >> advantage/disadvantage of the body of 'escapeVelocity' not being >> monadic). > > In my opinion the implicit parameters don't make things simpler, only less > portable, that's why I prefer the Reader monad. They also seem to be removed from

Re: Fwd: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Henning Thielemann
Bjorn Buckwalter schrieb: On Mon, Aug 18, 2008 at 2:02 PM, Henning Thielemann <[EMAIL PROTECTED]> wrote: >> Instead of muEarth :: GravitationalParameter a muEarth = ??? escapeVelocity :: a escapeVelocity = ... muEarth ... you would write data AstroData a = AstroData { muEarth ::

Fwd: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Bjorn Buckwalter
On Mon, Aug 18, 2008 at 2:02 PM, Henning Thielemann <[EMAIL PROTECTED]> wrote: > > On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: > >> On Mon, Aug 18, 2008 at 11:16 AM, Henning Thielemann >> <[EMAIL PROTECTED]> wrote: >>> >>> On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: >>> I would like to know

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Henning Thielemann
On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: On Mon, Aug 18, 2008 at 11:16 AM, Henning Thielemann <[EMAIL PROTECTED]> wrote: On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: I would like to know if there is any consensus on what is the best way to make such a data structure accessible in pure f

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Henning Thielemann
On Mon, 18 Aug 2008, Brandon S. Allbery KF8NH wrote: On 2008 Aug 18, at 11:16, Henning Thielemann wrote: know implicit parameters break referential transparency. http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue2/FunWithLinearImplicitParameters Are you making the same mistake I did?

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Brandon S. Allbery KF8NH
On 2008 Aug 18, at 11:16, Henning Thielemann wrote: know implicit parameters break referential transparency. http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue2/FunWithLinearImplicitParameters Are you making the same mistake I did? Linear implicit parameters are different from impli

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Brandon S. Allbery KF8NH
On 2008 Aug 18, at 10:59, Bjorn Buckwalter wrote: I would like to know if there is any consensus on what is the best way to make such a data structure accessible in pure functions. Passing it explicitly would be a mess. It seems that two options are to use either a Reader monad or implicit parame

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Bjorn Buckwalter
On Mon, Aug 18, 2008 at 11:16 AM, Henning Thielemann <[EMAIL PROTECTED]> wrote: > > On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: > >> I would like to know if there is any consensus on what is the best way >> to make such a data structure accessible in pure functions. Passing it >> explicitly would

Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Henning Thielemann
On Mon, 18 Aug 2008, Bjorn Buckwalter wrote: I would like to know if there is any consensus on what is the best way to make such a data structure accessible in pure functions. Passing it explicitly would be a mess. It seems that two options are to use either a Reader monad or implicit parameter

[Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Bjorn Buckwalter
All, I have a growing amount of astrodynamics code that relies on various physical "constants". The problem with these so called "constants" are that they either aren't really constants or aren't well known. An example is the leap second table (see Data.Time.Clock.TAI). I'd like to be able to fetc

[Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-18 Thread Bjorn Buckwalter
All, I have a growing amount of astrodynamics code that relies on various physical "constants". The problem with these so called "constants" are that they either aren't really constants or aren't well known. An example is the leap second table (see Data.Time.Clock.TAI). I'd like to be able to fetc