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. Pure function with timeout (Alex Rozenshteyn) 2. Re: Pure function with timeout (Alex Rozenshteyn) 3. Re: Pure function with timeout (Alex Rozenshteyn) 4. Re: Monads (Brent Yorgey) 5. Re: Monads (Patrick Lynch) 6. Nested data types and bisimilarity (dan portin) 7. Re: Nested data types and bisimilarity (dan portin) ---------------------------------------------------------------------- Message: 1 Date: Fri, 4 Mar 2011 14:04:55 -0500 From: Alex Rozenshteyn <rpglove...@gmail.com> Subject: [Haskell-beginners] Pure function with timeout To: Haskell Beginners <beginners@haskell.org> Message-ID: <aanlktikuhcqzs5dacegidk7bkmpr6iqxb47mth+fc...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I read http://www.haskell.org/haskellwiki/Timing_out_computations I thought I saw an issue and tested it: http://hpaste.org/44512/timed_iteration IMO, the timeout function should return the last iterated value when it is signaled, and not the next one after the signal. Is there a convention for this behavior? -- Alex R -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110304/05019642/attachment-0001.htm> ------------------------------ Message: 2 Date: Fri, 4 Mar 2011 14:22:40 -0500 From: Alex Rozenshteyn <rpglove...@gmail.com> Subject: Re: [Haskell-beginners] Pure function with timeout To: Haskell Beginners <beginners@haskell.org> Message-ID: <aanlktins_vuf2yxkazp3zb8mj+h9q8vriwrlxeywm...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" http://hpaste.org/44514/timed_iteration_try_2 seems to work but seems inelegant. On Fri, Mar 4, 2011 at 2:04 PM, Alex Rozenshteyn <rpglove...@gmail.com>wrote: > I read http://www.haskell.org/haskellwiki/Timing_out_computations > I thought I saw an issue and tested it: > http://hpaste.org/44512/timed_iteration > > IMO, the timeout function should return the last iterated value when it is > signaled, and not the next one after the signal. > > Is there a convention for this behavior? > > -- > Alex R > > -- Alex R -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110304/cf084f10/attachment-0001.htm> ------------------------------ Message: 3 Date: Fri, 4 Mar 2011 14:56:56 -0500 From: Alex Rozenshteyn <rpglove...@gmail.com> Subject: Re: [Haskell-beginners] Pure function with timeout To: Haskell Beginners <beginners@haskell.org> Message-ID: <aanlktimo9_ae1w+ewmmnn5zj7xu_p+6zkzec1pnhu...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" http://hpaste.org/paste/44514/timed_iteration_try_3#p44516 Using IORefs instead of MVars; seems to work fine and seems conceptually better. On Fri, Mar 4, 2011 at 2:22 PM, Alex Rozenshteyn <rpglove...@gmail.com>wrote: > http://hpaste.org/44514/timed_iteration_try_2 > > seems to work but seems inelegant. > > > On Fri, Mar 4, 2011 at 2:04 PM, Alex Rozenshteyn <rpglove...@gmail.com>wrote: > >> I read http://www.haskell.org/haskellwiki/Timing_out_computations >> I thought I saw an issue and tested it: >> http://hpaste.org/44512/timed_iteration >> >> IMO, the timeout function should return the last iterated value when it is >> signaled, and not the next one after the signal. >> >> Is there a convention for this behavior? >> >> -- >> Alex R >> >> > > > -- > Alex R > > -- Alex R -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110304/12abfbd8/attachment-0001.htm> ------------------------------ Message: 4 Date: Fri, 4 Mar 2011 15:07:07 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Monads To: beginners@haskell.org Message-ID: <20110304200707.ga13...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Wed, Mar 02, 2011 at 04:38:07PM -0500, Patrick Lynch wrote: > > ----- Original Message ----- From: "Brent Yorgey" > <byor...@seas.upenn.edu> > To: <beginners@haskell.org> > Sent: Wednesday, March 02, 2011 10:37 AM > Subject: Re: [Haskell-beginners] Monads > > > >On Wed, Mar 02, 2011 at 10:04:38AM -0500, Patrick Lynch wrote: > >>Daniel, > >>Thank you...I understand now... > >>Good day > >> > >> instance Functor Maybe where > >> fmap f (Just x) = Just (f x) > >> fmap f Nothing = Nothing > > > >So you are confused about this code? Can you be more specific what > >you are confused about? Try thinking carefully about all the types > >involved. What is the type of f? (You already answered this: a -> b.) > >What is the type of (Just x)? The type of x? What type is required on > >the right hand side of the = ? And so on. > > > -Hi Brent > I know that Maybe type is: data Maybe a = Nothing | Just a > ...so, I assume that the type to the right of the '=' should be > Maybe a.. Not quite. Let's look again at the type of fmap here: fmap :: (a -> b) -> Maybe a -> Maybe b So fmap will be taking *two* parameters, the first of type (a -> b), the second of type Maybe a. Then it needs to return something of type Maybe b (so this is what will be on the right hand side of the =). > instance Functor Maybe where > fmap Nothing = Nothing > fmap Just x = Just x You're missing the first argument to fmap (the one of type a -> b). Let's call it f. Since the second argument is of type (Maybe a) you're right that we should handle all cases (Nothing and Just). fmap f Nothing = Nothing so here we need to return something of type 'Maybe b'. Well, we don't have any values of type b, so the only thing we can do is return Nothing. fmap f (Just x) = ? The reason we need the parentheses around (Just x) is simply that otherwise the compiler thinks we are writing a definition of fmap that takes three arguments: f, Just, and x, but that doesn't make sense. Now, here f has type (a -> b), and (Just x) has type (Maybe a), hence x has type a. If we apply f to x we get something of type b, so we can define fmap f (Just x) = Just (f x) Does that make sense? -Brent ------------------------------ Message: 5 Date: Fri, 04 Mar 2011 17:20:27 -0500 From: "Patrick Lynch" <kmandpjly...@verizon.net> Subject: Re: [Haskell-beginners] Monads To: "Brent Yorgey" <byor...@seas.upenn.edu>, <beginners@haskell.org> Message-ID: <8E513E580E9F409FB19DE100517B4C15@UserPC> Content-Type: text/plain; format=flowed; charset=iso-8859-1; reply-type=original Good afternoon, It does make sense...thank you... I've just completed the online Haskell publication: "Learn You a Haskell for Great Good" -- see url: http://learnyouahaskell.com/chapters It will be available in book form this month from Amazon...I've purchased a copy of it... It shows the relationship between Functors, Applicative Functors, Monoids and Monads... It also contains many examples... I found it to be at a programmer's level... I think that I'm at a point where I know what I don't know.. I'll proceed onto the book: "Haskell The Craft of Functional Programming" and see if I can understand Monads in it... I'd love to take a crack at Category Theory [my mathematics is good] but this looks like a formidable task... I'll proceed using the Monad classes and instances as is - and hope that at some point I'll be able to create my own Monads... I'm an independent software consultant, been doing it for 30 years, and I'm trying to choose between Haskell, F# , C#-VB.Net or Ruby on Rails... Good weekend btw: can you create a class in Haskell -[I'm guessing the answer to this is no -- see below, it doesn't work]? class MyCalculator a where myadd::( Num a) => a -> a -> a myAdd x y = x + y ----- Original Message ----- From: "Brent Yorgey" <byor...@seas.upenn.edu> To: <beginners@haskell.org> Cc: "Patrick Lynch" <kmandpjly...@verizon.net> Sent: Friday, March 04, 2011 3:07 PM Subject: Re: [Haskell-beginners] Monads > On Wed, Mar 02, 2011 at 04:38:07PM -0500, Patrick Lynch wrote: >> >> ----- Original Message ----- From: "Brent Yorgey" >> <byor...@seas.upenn.edu> >> To: <beginners@haskell.org> >> Sent: Wednesday, March 02, 2011 10:37 AM >> Subject: Re: [Haskell-beginners] Monads >> >> >> >On Wed, Mar 02, 2011 at 10:04:38AM -0500, Patrick Lynch wrote: >> >>Daniel, >> >>Thank you...I understand now... >> >>Good day >> >> >> >> instance Functor Maybe where >> >> fmap f (Just x) = Just (f x) >> >> fmap f Nothing = Nothing >> > >> >So you are confused about this code? Can you be more specific what >> >you are confused about? Try thinking carefully about all the types >> >involved. What is the type of f? (You already answered this: a -> b.) >> >What is the type of (Just x)? The type of x? What type is required on >> >the right hand side of the = ? And so on. >> >> >> -Hi Brent >> I know that Maybe type is: data Maybe a = Nothing | Just a >> ...so, I assume that the type to the right of the '=' should be >> Maybe a.. > > Not quite. Let's look again at the type of fmap here: > > fmap :: (a -> b) -> Maybe a -> Maybe b > > So fmap will be taking *two* parameters, the first of type (a -> b), > the second of type Maybe a. Then it needs to return something of type > Maybe b (so this is what will be on the right hand side of the =). > >> instance Functor Maybe where >> fmap Nothing = Nothing >> fmap Just x = Just x > > You're missing the first argument to fmap (the one of type a -> b). > Let's call it f. Since the second argument is of type (Maybe a) > you're right that we should handle all cases (Nothing and Just). > > fmap f Nothing = Nothing > > so here we need to return something of type 'Maybe b'. Well, we don't > have any values of type b, so the only thing we can do is return > Nothing. > > fmap f (Just x) = ? > > The reason we need the parentheses around (Just x) is simply that > otherwise the compiler thinks we are writing a definition of fmap that > takes three arguments: f, Just, and x, but that doesn't make sense. > > Now, here f has type (a -> b), and (Just x) has type (Maybe a), hence > x has type a. If we apply f to x we get something of type b, so we > can define > > fmap f (Just x) = Just (f x) > > Does that make sense? > > -Brent ------------------------------ Message: 6 Date: Fri, 4 Mar 2011 18:04:40 -0800 From: dan portin <danpor...@gmail.com> Subject: [Haskell-beginners] Nested data types and bisimilarity To: beginners@haskell.org Message-ID: <AANLkTi=1_s+7Wxcumr6d8mCp=evr2mtoegrbupqmx...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I asked this question in another location, but perhaps this is a better palce. It's unclear to me how conditions for a relation to be a bisimulation on nested data types can be generated. I understand, by analogy with streams and binary trees, how to define such conditions for regular types. However, consider the types T a = T a [T a] N a = N (T [N a]) and a relation R over then. What conditions must be fulfilled for R to a bisimulation? In particular, how is the nesting of a list (or tree) dealt with? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110304/b2a1b898/attachment-0001.htm> ------------------------------ Message: 7 Date: Fri, 4 Mar 2011 18:32:40 -0800 From: dan portin <danpor...@gmail.com> Subject: Re: [Haskell-beginners] Nested data types and bisimilarity To: beginners@haskell.org Message-ID: <aanlktimrcrjw_5dd68xv5wpoagy6mw2221ldr6ah8...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Actually, let me rephrase the question. I know that a relation R over streams is a bisimulation if, for all lists l1 and l2, (a) their heads are equal and their tails are in the relation R, or (b) both l1 and l2 are empty. Similarly, I know that a relation R over in binary trees is a bisimulation if, for all trees t1 and t2, the values at the root node of t1 and t2 are equal, and the left and right subtrees of t1 and t2 are in the relation R. From the definition of a bisimulation, the conditions for a relation R over types constructed from arrow, cross, and so on, is easy to derive. However, suppose I have a data type data N a = N a [N a] By analogy, I might suppose that a relation R over trees t1 and t2 of type N a is a bisimulation if (a) the values at their root node are equal, and (b) their forests are equal. However, proving equality using this definition can lead to a circular proof. For instance, it might be the case that the values at the roots of t1 and t2 are equal, but that the head of the forests of t1 and t2 are, again, t1 and t2! (that is, assume T(t1,t2), and if their root values are equal, show that their forests are equal; if each is an infinite list, show that their heads are equal, but perhaps their heads are t1 and t2!). So I am slightly confused as to how equality of such types can be proved by the bisimulation method. In fact, I'm confused as to what the appropriate conditions are! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110304/344c4f16/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 33, Issue 5 ****************************************