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: Haskell described as a "rigid" language (Colin Paul Adams) 2. Re: Haskell described as a "rigid" language (Daniel Fischer) 3. Re: How to model this in haskell, get rid of my OO thinking? (hask...@lonely-star.org) 4. Re: Haskell described as a "rigid" language (aditya siram) 5. Re: How to model this in haskell, get rid of my OO thinking? (Lyndon Maydwell) 6. Re: How to model this in haskell, get rid of my OO thinking? (Nathan Huesken) 7. Re: How to model this in haskell, get rid of my OO thinking? (Lyndon Maydwell) ---------------------------------------------------------------------- Message: 1 Date: Tue, 18 May 2010 11:13:20 +0100 From: Colin Paul Adams <co...@colina.demon.co.uk> Subject: Re: [Haskell-beginners] Haskell described as a "rigid" language To: edgar klerks <edgar.kle...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <m3tyq5cybj....@colina.demon.co.uk> Content-Type: text/plain; charset=us-ascii >>>>> "Edgar" == edgar klerks <edgar.kle...@gmail.com> writes: Edgar> Probably dumb question, but was it the difference between Edgar> rigid and inflexible in this context (I am not native english Edgar> speaker)? Edgar> Google define gives me this: Edgar> Rigid means: Edgar> * incapable of compromise or flexibility * inflexible: Edgar> incapable of adapting or changing to meet circumstances; "a Edgar> rigid disciplinarian"; "an inflexible law"; "an unbending Edgar> will to dominate" Interesting. that's not what I would expect. Wikipedia seems more on the ball to me. -- Colin Adams Preston Lancashire () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments ------------------------------ Message: 2 Date: Tue, 18 May 2010 12:46:40 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] Haskell described as a "rigid" language To: beginners@haskell.org Message-ID: <201005181246.40312.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" On Tuesday 18 May 2010 12:13:20, Colin Paul Adams wrote: > >>>>> "Edgar" == edgar klerks <edgar.kle...@gmail.com> writes: > > Edgar> Probably dumb question, but was it the difference between > Edgar> rigid and inflexible in this context (I am not native english > Edgar> speaker)? > > Edgar> Google define gives me this: > > Edgar> Rigid means: > > Edgar> * incapable of compromise or flexibility * inflexible: > Edgar> incapable of adapting or changing to meet circumstances; "a > Edgar> rigid disciplinarian"; "an inflexible law"; "an unbending > Edgar> will to dominate" > > Interesting. that's not what I would expect > > Wikipedia seems more on the ball to me. Could you elaborate a bit, please? Which articles in Wikipedia, for example (the disambiguation page for rigidity gives like explanations [excepting technical terms in mathematics], I haven't found an article for inflexible[ibility], the wiktionary definition is alike again)? I thought rigid and inflexible are fairly closely related, though not synonyms. Google define seems to agree. ------------------------------ Message: 3 Date: Tue, 18 May 2010 09:28:45 -0400 From: hask...@lonely-star.org Subject: Re: [Haskell-beginners] How to model this in haskell, get rid of my OO thinking? To: Biginners Haskell Mailinglist <beginners@haskell.org> Message-ID: <20100518092845.42f17...@samzwo.tch.harvard.edu> Content-Type: text/plain; charset=US-ASCII Hi, Thanks, I think I am starting to get it :). But let me extend my example. Assume, (in C++) ScreenObject also has a abstract function "update" implemented in SpaceShip and Rocket and doing something completly different for both of them. Now there are a lot of ScreenObjects in the "world" which have to be updated in every frame. This is done by having a list of pointers to ScreenObjects (objects) and a updateWorld function which looks like this (simplified): void updateWorld() { for(o in objects) o->update(); } How would you model this in haskell? Thanks! Nathan On Tue, 18 May 2010 11:33:08 +0200 edgar klerks <edgar.kle...@gmail.com> wrote: > He Nathan, > > I would create an data type (SpaceObject), which holds the Position > and an object. Then I create a typeclass for SpaceObject, which has > the function move in it. Functions which all objects have are moved > in the typeclass: > > > type Position = (Double, Double) > > data SpaceObject a = SO a Position > > data RocketObject = RocketObject { > stuff :: String > } > > data SpaceShipObject = SpaceShipObject { > bla :: Int > } > > type Rocket = SpaceObject RocketObject > type SpaceShip = SpaceObject SpaceShipObject > > class ScreenObject a where > move :: a -> Position -> a > > instance ScreenObject (SpaceObject obj) where > move (SO obj (x,y) ) (dx, dy) = SO obj (x + dx, y + dy) > ~ > > ~ > > ~ > > ~ > > On Tue, May 18, 2010 at 5:21 AM, <hask...@lonely-star.org> wrote: > > > Hi, > > > > I learning haskell and I am trying to understand how model certain > > things in it. > > As I have been doing a lot of C++ programming so far. Let's imagine > > we want to write a game. In the game there are spaceships and rocks > > (image something like astroids :) ). Now both spaceships and rocks > > have a position and can move. Spaceships can shoot, while rocks can > > explode. In C++, I would do (simplified): > > > > class ScreenObject > > { > > float x,y; > > void move(dx,dy){x+=dx;y+=dy;} > > }; > > > > class Spaceship : public ScreenObject > > { > > void shoot(){...} > > }; > > > > class Rocket : public ScreenObject > > { > > void explode(){...} > > }; > > > > But what would I do in haskell? Ok, I can define a typeclass > > "ScreenObjectType" that has a move function (taking an object, > > retuning an moved object). > > But I do not want to implement "move" for both Spaceship and Rocket. > > Can I somehow give a default implementation for move that works on > > any datatype having an "x" and "y" element? Or what would I do? > > Can I somehow define a "base datatype" holding a x and y member form > > which Spaceship and Rocket derive? > > I feel like I am thinking to much OOP here. > > But the point is, I guess, that I want to avoid code duplication! > > > > So I guess, it comes down to the questions: How would you model the > > scenario described above in haskell? > > > > Thanks! > > Nathan > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > > ------------------------------ Message: 4 Date: Tue, 18 May 2010 09:41:09 -0400 From: aditya siram <aditya.si...@gmail.com> Subject: Re: [Haskell-beginners] Haskell described as a "rigid" language To: Daniel Fischer <daniel.is.fisc...@web.de> Cc: beginners@haskell.org Message-ID: <aanlkting_ckedjscasgykstps0wgaeugcuyqu8dxi...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Yes I would agree that rigidity and flexibility are closely related, but I think in this case the connotation is more important. Rigid can negatively connote an imposing of your will onto others, and a general unwillingness to adapt to a situation or take advice. Flexibility has the opposite connotation and in this light they are at odds. On the other hand rigid positively connotes rigor, having an unwavering standard of quality. From this point of view something can be rigid and flexible - and perhaps Haskell is best seen in this light. It lets you do whatever you want so long as your ideas are pretty clear but it isn't forgiving to fuzziness of thought. That is frustrating to beginners like me whose thoughts are eternally fuzzy but I know this is my problem and not the languages'. -deech On 5/18/10, Daniel Fischer <daniel.is.fisc...@web.de> wrote: > On Tuesday 18 May 2010 12:13:20, Colin Paul Adams wrote: >> >>>>> "Edgar" == edgar klerks <edgar.kle...@gmail.com> writes: >> >> Edgar> Probably dumb question, but was it the difference between >> Edgar> rigid and inflexible in this context (I am not native english >> Edgar> speaker)? >> >> Edgar> Google define gives me this: >> >> Edgar> Rigid means: >> >> Edgar> * incapable of compromise or flexibility * inflexible: >> Edgar> incapable of adapting or changing to meet circumstances; "a >> Edgar> rigid disciplinarian"; "an inflexible law"; "an unbending >> Edgar> will to dominate" >> >> Interesting. that's not what I would expect >> >> Wikipedia seems more on the ball to me. > > Could you elaborate a bit, please? > Which articles in Wikipedia, for example (the disambiguation page for > rigidity gives like explanations [excepting technical terms in > mathematics], I haven't found an article for inflexible[ibility], the > wiktionary definition is alike again)? > > I thought rigid and inflexible are fairly closely related, though not > synonyms. Google define seems to agree. > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 5 Date: Tue, 18 May 2010 22:08:31 +0800 From: Lyndon Maydwell <maydw...@gmail.com> Subject: Re: [Haskell-beginners] How to model this in haskell, get rid of my OO thinking? To: hask...@lonely-star.org Cc: Biginners Haskell Mailinglist <beginners@haskell.org> Message-ID: <aanlktik82zmldbohw5fr3c_skjpdutwwhagcruwse...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 You would likely not use a void function and instead map over the objects in the world: updateWorld :: World -> World updateWorld = fmap update This way your functions can remain pure. On Tue, May 18, 2010 at 9:28 PM, <hask...@lonely-star.org> wrote: > Hi, > > Thanks, I think I am starting to get it :). But let me extend my > example. > Assume, (in C++) ScreenObject also has a abstract function "update" > implemented in SpaceShip and Rocket and doing something completly > different for both of them. > Now there are a lot of ScreenObjects in the "world" which have to be > updated in every frame. This is done by having a list of pointers to > ScreenObjects (objects) and a updateWorld function which looks like > this (simplified): > > void updateWorld() > { > Â Â for(o in objects) > Â Â Â Â o->update(); > } > > How would you model this in haskell? > Thanks! > Nathan > > On Tue, 18 May 2010 11:33:08 +0200 > edgar klerks <edgar.kle...@gmail.com> wrote: > >> He Nathan, >> >> I would create an data type (SpaceObject), which holds the Position >> and an object. Then I create a typeclass for SpaceObject, which has >> the function move in it. Functions which all objects have are moved >> in the typeclass: >> >> >> type Position = (Double, Double) >> >> data SpaceObject a = SO a Position >> >> data RocketObject = RocketObject { >> Â Â Â Â Â Â Â Â stuff :: String >> Â Â Â Â } >> >> data SpaceShipObject = SpaceShipObject { >> Â Â Â Â Â Â Â Â bla :: Int >> Â Â Â Â } >> >> type Rocket = SpaceObject RocketObject >> type SpaceShip = SpaceObject SpaceShipObject >> >> class ScreenObject a where >> Â Â Â Â move :: a -> Position -> a >> >> instance ScreenObject (SpaceObject obj) where >> Â Â Â Â move (SO obj (x,y) ) (dx, dy) Â = SO obj (x + dx, y + dy) >> ~ >> >> ~ >> >> ~ >> >> ~ >> >> On Tue, May 18, 2010 at 5:21 AM, <hask...@lonely-star.org> wrote: >> >> > Hi, >> > >> > I learning haskell and I am trying to understand how model certain >> > things in it. >> > As I have been doing a lot of C++ programming so far. Let's imagine >> > we want to write a game. In the game there are spaceships and rocks >> > (image something like astroids :) ). Now both spaceships and rocks >> > have a position and can move. Spaceships can shoot, while rocks can >> > explode. In C++, I would do (simplified): >> > >> > class ScreenObject >> > { >> > Â float x,y; >> > Â void move(dx,dy){x+=dx;y+=dy;} >> > }; >> > >> > class Spaceship : public ScreenObject >> > { >> > Â Â void shoot(){...} >> > }; >> > >> > class Rocket : public ScreenObject >> > { >> > Â Â void explode(){...} >> > }; >> > >> > But what would I do in haskell? Ok, I can define a typeclass >> > "ScreenObjectType" that has a move function (taking an object, >> > retuning an moved object). >> > But I do not want to implement "move" for both Spaceship and Rocket. >> > Can I somehow give a default implementation for move that works on >> > any datatype having an "x" and "y" element? Or what would I do? >> > Can I somehow define a "base datatype" holding a x and y member form >> > which Spaceship and Rocket derive? >> > I feel like I am thinking to much OOP here. >> > But the point is, I guess, that I want to avoid code duplication! >> > >> > So I guess, it comes down to the questions: How would you model the >> > scenario described above in haskell? >> > >> > Thanks! >> > Nathan >> > _______________________________________________ >> > Beginners mailing list >> > Beginners@haskell.org >> > http://www.haskell.org/mailman/listinfo/beginners >> > >> >> >> > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 6 Date: Tue, 18 May 2010 10:29:24 -0400 From: Nathan Huesken <hask...@lonely-star.org> Subject: Re: [Haskell-beginners] How to model this in haskell, get rid of my OO thinking? To: Biginners Haskell Mailinglist <beginners@haskell.org> Message-ID: <20100518102924.59716...@samzwo.tch.harvard.edu> Content-Type: text/plain; charset=UTF-8 Hey, Yes, that makes sense. Still, how would the "World" object look? How do I do a list of abstract base classes in haskell? On Tue, 18 May 2010 22:08:31 +0800 Lyndon Maydwell <maydw...@gmail.com> wrote: > You would likely not use a void function and instead map over the > objects in the world: > > updateWorld :: World -> World > updateWorld = fmap update > > This way your functions can remain pure. > > On Tue, May 18, 2010 at 9:28 PM, <hask...@lonely-star.org> wrote: > > Hi, > > > > Thanks, I think I am starting to get it :). But let me extend my > > example. > > Assume, (in C++) ScreenObject also has a abstract function "update" > > implemented in SpaceShip and Rocket and doing something completly > > different for both of them. > > Now there are a lot of ScreenObjects in the "world" which have to be > > updated in every frame. This is done by having a list of pointers to > > ScreenObjects (objects) and a updateWorld function which looks like > > this (simplified): > > > > void updateWorld() > > { > > Â Â for(o in objects) > > Â Â Â Â o->update(); > > } > > > > How would you model this in haskell? > > Thanks! > > Nathan > > > > On Tue, 18 May 2010 11:33:08 +0200 > > edgar klerks <edgar.kle...@gmail.com> wrote: > > > >> He Nathan, > >> > >> I would create an data type (SpaceObject), which holds the Position > >> and an object. Then I create a typeclass for SpaceObject, which has > >> the function move in it. Functions which all objects have are moved > >> in the typeclass: > >> > >> > >> type Position = (Double, Double) > >> > >> data SpaceObject a = SO a Position > >> > >> data RocketObject = RocketObject { > >> Â Â Â Â Â Â Â Â stuff :: String > >> Â Â Â Â } > >> > >> data SpaceShipObject = SpaceShipObject { > >> Â Â Â Â Â Â Â Â bla :: Int > >> Â Â Â Â } > >> > >> type Rocket = SpaceObject RocketObject > >> type SpaceShip = SpaceObject SpaceShipObject > >> > >> class ScreenObject a where > >> Â Â Â Â move :: a -> Position -> a > >> > >> instance ScreenObject (SpaceObject obj) where > >> Â Â Â Â move (SO obj (x,y) ) (dx, dy) Â = SO obj (x + dx, y + dy) > >> ~ > >> > >> ~ > >> > >> ~ > >> > >> ~ > >> > >> On Tue, May 18, 2010 at 5:21 AM, <hask...@lonely-star.org> wrote: > >> > >> > Hi, > >> > > >> > I learning haskell and I am trying to understand how model > >> > certain things in it. > >> > As I have been doing a lot of C++ programming so far. Let's > >> > imagine we want to write a game. In the game there are > >> > spaceships and rocks (image something like astroids :) ). Now > >> > both spaceships and rocks have a position and can move. > >> > Spaceships can shoot, while rocks can explode. In C++, I would > >> > do (simplified): > >> > > >> > class ScreenObject > >> > { > >> > Â float x,y; > >> > Â void move(dx,dy){x+=dx;y+=dy;} > >> > }; > >> > > >> > class Spaceship : public ScreenObject > >> > { > >> > Â Â void shoot(){...} > >> > }; > >> > > >> > class Rocket : public ScreenObject > >> > { > >> > Â Â void explode(){...} > >> > }; > >> > > >> > But what would I do in haskell? Ok, I can define a typeclass > >> > "ScreenObjectType" that has a move function (taking an object, > >> > retuning an moved object). > >> > But I do not want to implement "move" for both Spaceship and > >> > Rocket. Can I somehow give a default implementation for move > >> > that works on any datatype having an "x" and "y" element? Or > >> > what would I do? Can I somehow define a "base datatype" holding > >> > a x and y member form which Spaceship and Rocket derive? > >> > I feel like I am thinking to much OOP here. > >> > But the point is, I guess, that I want to avoid code duplication! > >> > > >> > So I guess, it comes down to the questions: How would you model > >> > the scenario described above in haskell? > >> > > >> > Thanks! > >> > Nathan > >> > _______________________________________________ > >> > Beginners mailing list > >> > Beginners@haskell.org > >> > http://www.haskell.org/mailman/listinfo/beginners > >> > > >> > >> > >> > > > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > ------------------------------ Message: 7 Date: Tue, 18 May 2010 22:45:02 +0800 From: Lyndon Maydwell <maydw...@gmail.com> Subject: Re: [Haskell-beginners] How to model this in haskell, get rid of my OO thinking? To: Nathan Huesken <hask...@lonely-star.org> Cc: Biginners Haskell Mailinglist <beginners@haskell.org> Message-ID: <aanlktimkgovhuac9m8-t0z_qcezhorc_dzdxbaote...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 World could be anything really, maybe a list of objects, or something much more involved. From my use of fmap I've implied that it is an instance of the Functor typeclass, but that was only a suggestion. I'm not sure what you're after with respect the the abstract base classes, but there's this diagram floating around of the haskell98 typeclasses: [ http://www.uni-bonn.de/~manfear/haskell-classhierarchy.php ]. Maybe this will help? I usually use the ":info" command on a class in ghci to find out some more about it, but I still have trouble finding a good class to use for any particular problem. Hope this was helpful. On Tue, May 18, 2010 at 10:29 PM, Nathan Huesken <hask...@lonely-star.org> wrote: > Hey, > > Yes, that makes sense. Still, how would the "World" object look? > How do I do a list of abstract base classes in haskell? > > On Tue, 18 May 2010 22:08:31 +0800 > Lyndon Maydwell <maydw...@gmail.com> wrote: > >> You would likely not use a void function and instead map over the >> objects in the world: >> >> updateWorld :: World -> World >> updateWorld = fmap update >> >> This way your functions can remain pure. >> >> On Tue, May 18, 2010 at 9:28 PM, Â <hask...@lonely-star.org> wrote: >> > Hi, >> > >> > Thanks, I think I am starting to get it :). But let me extend my >> > example. >> > Assume, (in C++) ScreenObject also has a abstract function "update" >> > implemented in SpaceShip and Rocket and doing something completly >> > different for both of them. >> > Now there are a lot of ScreenObjects in the "world" which have to be >> > updated in every frame. This is done by having a list of pointers to >> > ScreenObjects (objects) and a updateWorld function which looks like >> > this (simplified): >> > >> > void updateWorld() >> > { >> > Â Â for(o in objects) >> > Â Â Â Â o->update(); >> > } >> > >> > How would you model this in haskell? >> > Thanks! >> > Nathan >> > >> > On Tue, 18 May 2010 11:33:08 +0200 >> > edgar klerks <edgar.kle...@gmail.com> wrote: >> > >> >> He Nathan, >> >> >> >> I would create an data type (SpaceObject), which holds the Position >> >> and an object. Then I create a typeclass for SpaceObject, which has >> >> the function move in it. Functions which all objects have are moved >> >> in the typeclass: >> >> >> >> >> >> type Position = (Double, Double) >> >> >> >> data SpaceObject a = SO a Position >> >> >> >> data RocketObject = RocketObject { >> >> Â Â Â Â Â Â Â Â stuff :: String >> >> Â Â Â Â } >> >> >> >> data SpaceShipObject = SpaceShipObject { >> >> Â Â Â Â Â Â Â Â bla :: Int >> >> Â Â Â Â } >> >> >> >> type Rocket = SpaceObject RocketObject >> >> type SpaceShip = SpaceObject SpaceShipObject >> >> >> >> class ScreenObject a where >> >> Â Â Â Â move :: a -> Position -> a >> >> >> >> instance ScreenObject (SpaceObject obj) where >> >> Â Â Â Â move (SO obj (x,y) ) (dx, dy) Â = SO obj (x + dx, y + dy) >> >> ~ >> >> >> >> ~ >> >> >> >> ~ >> >> >> >> ~ >> >> >> >> On Tue, May 18, 2010 at 5:21 AM, <hask...@lonely-star.org> wrote: >> >> >> >> > Hi, >> >> > >> >> > I learning haskell and I am trying to understand how model >> >> > certain things in it. >> >> > As I have been doing a lot of C++ programming so far. Let's >> >> > imagine we want to write a game. In the game there are >> >> > spaceships and rocks (image something like astroids :) ). Now >> >> > both spaceships and rocks have a position and can move. >> >> > Spaceships can shoot, while rocks can explode. In C++, I would >> >> > do (simplified): >> >> > >> >> > class ScreenObject >> >> > { >> >> > Â float x,y; >> >> > Â void move(dx,dy){x+=dx;y+=dy;} >> >> > }; >> >> > >> >> > class Spaceship : public ScreenObject >> >> > { >> >> > Â Â void shoot(){...} >> >> > }; >> >> > >> >> > class Rocket : public ScreenObject >> >> > { >> >> > Â Â void explode(){...} >> >> > }; >> >> > >> >> > But what would I do in haskell? Ok, I can define a typeclass >> >> > "ScreenObjectType" that has a move function (taking an object, >> >> > retuning an moved object). >> >> > But I do not want to implement "move" for both Spaceship and >> >> > Rocket. Can I somehow give a default implementation for move >> >> > that works on any datatype having an "x" and "y" element? Or >> >> > what would I do? Can I somehow define a "base datatype" holding >> >> > a x and y member form which Spaceship and Rocket derive? >> >> > I feel like I am thinking to much OOP here. >> >> > But the point is, I guess, that I want to avoid code duplication! >> >> > >> >> > So I guess, it comes down to the questions: How would you model >> >> > the scenario described above in haskell? >> >> > >> >> > Thanks! >> >> > Nathan >> >> > _______________________________________________ >> >> > Beginners mailing list >> >> > Beginners@haskell.org >> >> > http://www.haskell.org/mailman/listinfo/beginners >> >> > >> >> >> >> >> >> >> > >> > _______________________________________________ >> > Beginners mailing list >> > Beginners@haskell.org >> > http://www.haskell.org/mailman/listinfo/beginners >> > >> > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 23, Issue 28 *****************************************