Re: [Haskell-cafe] Name that function =)

On 12/12/06, Conal Elliott
Try foo = liftM2, and check out the recent haskell thread "Cannot understand liftM2".
That's actually what I reached for first. The problem is that the arguments aren't monads: *Main> :t (uncurry renameFile) (uncurry renameFile) :: (FilePath, FilePath) -> IO () *Main> :t putDirs putDirs :: (String, String) -> IO () and liftM2 works on monadic arguments: liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r I need to somehow get the mapped elements to be applied to each of the arguments before they can be combined. Substituting liftM2 for (foo (>>)) yields: No instance for (Monad ((->) (String, String))) arising from use of `liftM2' at DCFiles.hs:30:9-14 Probable fix: add an instance declaration for (Monad ((->) (String, String))) The foo function does the job, so I assume that I'm trying to solve a different problem than liftM. I wouldn't be surprised if I was wrong, however. -- Lou.

On Dec 12, 2006, at 12:53 PM, Louis J Scoras wrote:
On 12/12/06, Conal Elliott
wrote: Try foo = liftM2, and check out the recent haskell thread "Cannot understand liftM2".
That's actually what I reached for first. The problem is that the arguments aren't monads: (...) No instance for (Monad ((->) (String, String)))
Read the thread more completely; ((->) a) is indeed a monad, but you need to include an additional module to get the definition. -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On 12/12/06, Brandon S. Allbery KF8NH
Read the thread more completely; ((->) a) is indeed a monad, but you need to include an additional module to get the definition.
Ahh, okay I did see that. I thought that importing Control.Monad would be sufficient. What I didn't realize is that even though the documentation for Control.Monad says that (->(r)) is an instance, it must not be defined there. Importing Control.Monad.Reader indeed does make it work, thanks for pointing that out again. So I guess my next question would be, looking here http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html How do I figure out that the instance declaration is actually in the Reader module? Is it just because the (->) constructor is special -- or just not hyperlinked? -- Lou.

On 12/12/06, Louis J Scoras
What I didn't realize is that even though the documentation for Control.Monad says that (->(r)) is an instance, it must not be defined there. Importing Control.Monad.Reader indeed does make it work, thanks for pointing that out again.
So I guess my next question would be, looking here
http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html
How do I figure out that the instance declaration is actually in the Reader module? Is it just because the (->) constructor is special -- or just not hyperlinked?
It's pretty subtle, but the Haddock there does list an instance of MonadReader r ((->) r). In newer GHC's the instance is also found in Control.Monad.Instances. In my opinion, it belongs in the Prelude. :) - Cale

On 12/12/06, Cale Gibbard
It's pretty subtle, but the Haddock there does list an instance of MonadReader r ((->) r).
Yup, I see that one. What I meant was that in the Mondad package it says that ((->) r) is an instance of Monad, but I can't find way to get from there to Reader.
In newer GHC's the instance is also found in Control.Monad.Instances. In my opinion, it belongs in the Prelude. :)
Hmm. Yeah, it seems like there aren't many monad instances imported into prelude. Just [], Maybe and IO. I'll have to keep that in mind. Thanks for your help everybody. -- Lou.
participants (3)
-
Brandon S. Allbery KF8NH
-
Cale Gibbard
-
Louis J Scoras