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: Beginners Digest, Vol 56, Issue 33 (Brandon Allbery) 2. Re: Beginners Digest, Vol 56, Issue 33 (Brent Yorgey) 3. Re: Use a list as data for a data type? (Karl Voelker) ---------------------------------------------------------------------- Message: 1 Date: Fri, 22 Feb 2013 19:42:06 -0500 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] Beginners Digest, Vol 56, Issue 33 To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Message-ID: <CAKFCL4XKfsLQLKro61ey=_Kxa=j9taz7k_yo13s8akhvlpo...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Fri, Feb 22, 2013 at 7:27 PM, xiao Ling <lingx...@seas.upenn.edu> wrote: > h :: M Int -> M Int -> M Int > h x y = bind ( \x-> g x y ) x > > where g is > > g :: Int -> W Int -> W Int > g x y = y >>= (return . (+x)) > > for the monad: > > data M a = M a deriving Show > > Now I am a little confused, how can you put x in g if it takes an Int as > first parameter but x is M Int? > Because it's a different "x". Lemme rewrite it slightly: h :: M Int -> M Int -> M Int h x y = bind ( \w -> g w y ) x All I did was replace the inner "x" with "w", to demonstrate that it has no relationship to the outer "x"; the \... -> syntax introduces new local bindings unrelated to any outside of it, in this case for "w" (or what he had "x", shadowing the original binding of "x" within the lambda). -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130222/8a72a12e/attachment-0001.htm> ------------------------------ Message: 2 Date: Fri, 22 Feb 2013 19:44:05 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Beginners Digest, Vol 56, Issue 33 To: beginners@haskell.org Message-ID: <20130223004405.ga17...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Fri, Feb 22, 2013 at 07:27:28PM -0500, xiao Ling wrote: > Hi All: How do you define a function of signature h :: M Int -> M Int -> M > Int so that h ( M x ) ( M y ) = M ( x + y ), but without unwrapping the > value from the monad? > > This question is from the article "Trivial Monad" found at > http://blog.sigfpe.com/2007/04/trivial-monad.html. The provided answer is > > h x y = x >>= (\x -> g x y) > > Now I am a little confused, how can you put x in g if it takes an Int as > first parameter but x is M Int? I think your confusion may stem from the fact that there are *two different* things named 'x' in the above code. The x's on the right hand side of the >>= shadow the x on the left hand side. This is confusing and poor style; a better way to write it would be h x y = x >>= (\i -> g i y) If you study the type of >>= you will see that i indeed has type Int, as required for the first argument of g. -Brent ------------------------------ Message: 3 Date: Fri, 22 Feb 2013 19:48:20 -0800 From: Karl Voelker <ktvoel...@gmail.com> Subject: Re: [Haskell-beginners] Use a list as data for a data type? To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Message-ID: <CAFfow0wzUMVne5=j1675ul0uujyw4a3vaaukahp9c86sjxa...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Fri, Feb 22, 2013 at 12:40 PM, Bryce Verdier <bryceverd...@gmail.com>wrote: > Brent, > > Thank you for the responses. I appreciate it. Bummer about there not being > some kind of built-in/generic shortcut. > > Bryce I am curious about what motivated your question, since it's hard to imagine a simpler alternative to writing "IpAddress 1 2 3 4". -Karl Voelker -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130222/cd063ba5/attachment-0001.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 56, Issue 38 *****************************************