Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: monad nomad gonad gomad (prad) 2. Re: global variables (prad) 3. Re: monad nomad gonad gomad (Ertugrul Soeylemez) 4. Re: Re: global variables (Brandon S Allbery KF8NH) 5. Re: Re: global variables (Ozgur Akgun) 6. Re: global variables (Ertugrul Soeylemez) 7. Re: Re: monad nomad gonad gomad (Thomas) ---------------------------------------------------------------------- Message: 1 Date: Sun, 15 Aug 2010 10:52:26 -0700 From: prad <p...@towardsfreedom.com> Subject: [Haskell-beginners] Re: monad nomad gonad gomad To: beginners@haskell.org Message-ID: <20100815105226.33c50...@gom> Content-Type: text/plain; charset=US-ASCII On Sun, 15 Aug 2010 16:43:09 +0200 Ertugrul Soeylemez <e...@ertes.de> wrote: > I'm not sure whether you are reading our posts, but we have > explained in detail the difference. Once understood, you won't get > errors like that anymore. > > As a well meant suggestion, you have to actually read the answers to > your posts, even if they are long. > ertugrul, believe me i read the posts (more than a few times) - especially yours in fact and am very appreciative. however, it takes me a while to understand what's going on - even to connect similar ideas together. i certainly don't mind long posts either, but i am still having difficulties putting the ideas together. i tend to be a bit slow anyway and keep thinking in python terms. i intend to respond once i understand the ideas better. for instance, what you wrote here made sense to me: ======== let readBlahTxt = readFile "blah.txt" content <- readBlahTxt This should show the difference more clearly. ======== however, i still can't quite connect it to the idea of what it has to do with getting monad data out of a monad and into the pure realm. late last night, though, i was able to do so, but it took while. > Posting essentially the same questions over and over gets you nowhere. > agreed and i apologize. my problem is that i don't even see that it is the same question. as you have pointed out once before, "You're still thinking way too complicated." i think what happens is i keep trying different things over and over again. that affects my thinking no doubt. i should likely think more and try less. > A monad is just a way to combine computations. > this wasn't clear to me till now even though i had read your continuing exchange with kyle and the example both of you were discussing regarding >>= (and i had read up on the operator and even tried it). > I don't like to mention my own one > i would very much like to see yours. > I agree with Brent > i think brent's delightful blog post describes my present dilemmas ... except i haven't quite gotten to the point of being able to say "monads are burritos" ... so i think there is likely still hope for me. ;) -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's ------------------------------ Message: 2 Date: Sun, 15 Aug 2010 11:04:11 -0700 From: prad <p...@towardsfreedom.com> Subject: [Haskell-beginners] Re: global variables To: beginners@haskell.org Message-ID: <20100815110411.1daa5...@gom> Content-Type: text/plain; charset=US-ASCII On Wed, 11 Aug 2010 22:25:45 +0200 Ertugrul Soeylemez <e...@ertes.de> wrote: > My way of doing this is the following (snippet): > > import Control.Applicative > import MonadLib > > type DatabaseT = ReaderT Connection > > myApplication :: DatabaseT IO () > myApplication = do > dbConn <- ask > inBase $ runRaw dbConn "SELECT now();" > > runDatabaseT :: BaseM m IO => DatabaseT m a -> m a > runDatabaseT c = do > conn <- inBase $ connectPostgreSQL "" > runReaderT (Config conn) c > > main :: IO () > main = runDatabaseT myApplication > thank you ertugrul. i understand the explanations you and MAN have provided regarding global variables. however, i don't understand what you have done above despite the illustrative game example. i've been in the middle of trying to get info out of a monad (as indicated in other posts) and have finally gotten by the errors (although the understanding hasn't quite congealed yet). as a result i haven't been able to try to incorporate the above yet (which is why i haven't responded till now). i did note that MonadLib doesn't seem to exist, so is that something i get from cabal? is ask part of it too? > What you want is not a global variable, but a convenient way to pass > environment values to functions and computations. > yes that is what i want, but i haven't gotten the gist of the code you have provided me with yet. i need to understand types better for one thing. > I hope this helps. > it will. i've flagged your post and will come back to it after acquiring a bit more competence - as well as repetitive readings. -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's ------------------------------ Message: 3 Date: Sun, 15 Aug 2010 21:11:52 +0200 From: Ertugrul Soeylemez <e...@ertes.de> Subject: [Haskell-beginners] Re: monad nomad gonad gomad To: beginners@haskell.org Message-ID: <20100815211152.4ad15...@tritium.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII prad <p...@towardsfreedom.com> wrote: > On Sun, 15 Aug 2010 16:43:09 +0200 > Ertugrul Soeylemez <e...@ertes.de> wrote: > > > I'm not sure whether you are reading our posts, but we have > > explained in detail the difference. Once understood, you won't get > > errors like that anymore. > > > > As a well meant suggestion, you have to actually read the answers to > > your posts, even if they are long. > > believe me i read the posts (more than a few times) - especially yours > in fact and am very appreciative. however, it takes me a while to > understand what's going on - even to connect similar ideas together. i > certainly don't mind long posts either, but i am still having > difficulties putting the ideas together. i tend to be a bit slow > anyway and keep thinking in python terms. > > i intend to respond once i understand the ideas better. for instance, > what you wrote here made sense to me: > > ======== > let readBlahTxt = readFile "blah.txt" > content <- readBlahTxt > > This should show the difference more clearly. > ======== > > however, i still can't quite connect it to the idea of what it has to > do with getting monad data out of a monad and into the pure realm. > late last night, though, i was able to do so, but it took while. I'd say don't bother. "Getting out of" is just a metaphor. Monads are no boxes. You have a monadic computation, which has a result, and you want to refer to this result, and that's all. let a = getLine b <- getLine In this example, 'a' is the same as 'getLine'. It's a computation, which reads a line from stdin. It's not the result of the computation (String), but the computation itself (IO String), because you defined 'a' and 'getLine' to be the same thing. On the other hand, 'b' is the result. You could just as well write: b <- a Just remember this: You have an IO computation? You want to refer to its result? Fine, just use '<-'. That's it. Now what is meant by the "getting out of" metaphor? You can use the '<-' notation only inside of a monadic computation. In other words, even though you can refer to the result of getLine, ultimately you are making a new IO computation, which uses the result: readAndSquare :: IO Integer readAndSquare = do line <- getLine let n = read line return (n^2) readAndSquare is an IO computation itself and there is nothing you could do about it. As long as you refer to results of IO computations, if you go down the call tree, you will always end up in an IO computation. This is what people refer to as not being able to "get out of" IO. This is not true for the list monad: getFirstWord :: String -> String getFirstWord = head . words The list concept is also a monad, or in Haskell terms: [] is a monad. You are using the result of a monadic computation, namely 'words': words :: String -> [String] -- brackets style words :: String -> [] String -- prefix style But the getFirstWord function is itself not monadic (let's disregard the fact that strings are lists). Using the 'head' function head :: [a] -> a -- brackets style head :: [] a -> a -- prefix style you have broken out of the [] monad. There is no such function for the IO monad: breakOut :: IO a -> a Well, that's not entirely true. There is unsafePerformIO, which has exactly that type signature, but seriously, never use it. Especially as a beginner coming from the imperative world one is often tempted to use it, but don't. Using it is almost always the wrong approach, and as its name suggests a very unsafe one, too. > > Posting essentially the same questions over and over gets you > > nowhere. > > agreed and i apologize. my problem is that i don't even see that it is > the same question. as you have pointed out once before, "You're still > thinking way too complicated." > > i think what happens is i keep trying different things over and over > again. that affects my thinking no doubt. i should likely think more > and try less. In fact, I recommend not to think more, but to think less. Forget the word 'monad' and just concentrate on specific monads like IO or Maybe. At some point it will make click and suddenly everything gets clear. Everybody has this experience with monads (unless they give up). > > I don't like to mention my own one > > i would very much like to see yours. It's linked on the tutorials wiki page as "Understanding Haskell Monads". > > I agree with Brent > > i think brent's delightful blog post describes my present dilemmas ... > except i haven't quite gotten to the point of being able to say > "monads are burritos" ... so i think there is likely still hope for > me. ;) Try this [1]. ;) [1] http://blog.plover.com/prog/burritos.html Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 4 Date: Sun, 15 Aug 2010 15:42:25 -0400 From: Brandon S Allbery KF8NH <allb...@ece.cmu.edu> Subject: Re: [Haskell-beginners] Re: global variables To: beginners@haskell.org Message-ID: <4c684321.5080...@ece.cmu.edu> Content-Type: text/plain; charset=UTF-8 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8/15/10 14:04 , prad wrote: > i did note that MonadLib doesn't seem to exist, so is that something i > get from cabal? is ask part of it too? MonadLib is on Hackage, yes. "ask" is part of the MonadReader typeclass. - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxoQyEACgkQIn7hlCsL25XuZgCfQy4+KGvThqmFh0DPpfAEph/K bqEAn0Dmc0LnW40SMtblE6Jnl3AQWHJP =ldlg -----END PGP SIGNATURE----- ------------------------------ Message: 5 Date: Sun, 15 Aug 2010 20:50:03 +0100 From: Ozgur Akgun <ozgurak...@gmail.com> Subject: Re: [Haskell-beginners] Re: global variables To: Brandon S Allbery KF8NH <allb...@ece.cmu.edu> Cc: beginners@haskell.org Message-ID: <aanlktin4s3lqpx=pbzvwv+1acjjx4lk6hwvos2nmj...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On 15 August 2010 20:42, Brandon S Allbery KF8NH <allb...@ece.cmu.edu>wrote: > On 8/15/10 14:04 , prad wrote: > > is ask part of it too? > > "ask" is part of the MonadReader typeclass. > > as a side note, asking hoogle might help in such questions: http://www.haskell.org/hoogle/?hoogle=ask hth, Ozgur -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20100815/cbf36f5d/attachment-0001.html ------------------------------ Message: 6 Date: Sun, 15 Aug 2010 22:34:19 +0200 From: Ertugrul Soeylemez <e...@ertes.de> Subject: [Haskell-beginners] Re: global variables To: beginners@haskell.org Message-ID: <20100815223419.544ad...@tritium.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII Brandon S Allbery KF8NH <allb...@ece.cmu.edu> wrote: > On 8/15/10 14:04 , prad wrote: > > i did note that MonadLib doesn't seem to exist, so is that something > > i get from cabal? is ask part of it too? > > MonadLib is on Hackage, yes. "ask" is part of the MonadReader > typeclass. In MonadLib the class is named ReaderM, not MonadReader. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 7 Date: Mon, 16 Aug 2010 18:35:22 +0200 From: Thomas <hask...@phirho.com> Subject: Re: [Haskell-beginners] Re: monad nomad gonad gomad To: beginners@haskell.org Message-ID: <4c6968ca.3000...@phirho.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi prad! Reading the recent threads about Monads I decided to put my learning experience online. It might be of use to someone (maybe you?). http://codingcactus.wordpress.com/2010/08/16/writemonad1/ Regards, Thomas On 15.08.2010 19:52, prad wrote: > On Sun, 15 Aug 2010 16:43:09 +0200 > Ertugrul Soeylemez<e...@ertes.de> wrote: > >> I'm not sure whether you are reading our posts, but we have >> explained in detail the difference. Once understood, you won't get >> errors like that anymore. >> >> As a well meant suggestion, you have to actually read the answers to >> your posts, even if they are long. >> > ertugrul, > > believe me i read the posts (more than a few times) - especially yours > in fact and am very appreciative. however, it takes me a while to > understand what's going on - even to connect similar ideas together. i > certainly don't mind long posts either, but i am still having > difficulties putting the ideas together. i tend to be a bit slow anyway > and keep thinking in python terms. > > i intend to respond once i understand the ideas better. for instance, > what you wrote here made sense to me: > > > ======== > let readBlahTxt = readFile "blah.txt" > content<- readBlahTxt > > This should show the difference more clearly. > ======== > > however, i still can't quite connect it to the idea of what it has to > do with getting monad data out of a monad and into the pure realm. > late last night, though, i was able to do so, but it took while. > > >> Posting essentially the same questions over and over gets you nowhere. >> > agreed and i apologize. my problem is that i don't even see that it is > the same question. as you have pointed out once before, "You're still > thinking way too complicated." > > i think what happens is i keep trying different things over and over > again. that affects my thinking no doubt. i should likely think more > and try less. > > >> A monad is just a way to combine computations. >> > this wasn't clear to me till now even though i had read your continuing > exchange with kyle and the example both of you were discussing > regarding>>= (and i had read up on the operator and even tried it). > > >> I don't like to mention my own one >> > i would very much like to see yours. > > >> I agree with Brent >> > i think brent's delightful blog post describes my present dilemmas ... > except i haven't quite gotten to the point of being able to say "monads > are burritos" ... so i think there is likely still hope for me. ;) > ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 26, Issue 33 *****************************************