Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Jules Bean
Miguel Mitrofanov wrote: There's a third way, too, and I haven't seen anybody mention it yet I've noticed it, but there are some problems with this representation, so I decided not to mention it. It's OK as far as we don't want functions working on two areas - I don't see, how we can

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Miguel Mitrofanov
class Shape a where { intersect :: Shape b = a - b - Bool } data Shape a = { intersect :: Shape b = a - b - Bool } in fact, the syntax is rather similar, too! :) Um, well, and how are you going to implement it? ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Jules Bean
Miguel Mitrofanov wrote: class Shape a where { intersect :: Shape b = a - b - Bool } data Shape a = { intersect :: Shape b = a - b - Bool } in fact, the syntax is rather similar, too! :) Um, well, and how are you going to implement it? Yes, exactly. My only point is There

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Jules Bean
Felipe Lessa wrote: On Dec 18, 2007 7:51 AM, Jules Bean [EMAIL PROTECTED] wrote: class Shape a where { intersect :: Shape b = a - b - Bool } Shouldn't this be class Shape a where whatever class (Shape a, Shape b) = Intersectable a b where intersect :: a - b - Bool With your

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Felipe Lessa
On Dec 18, 2007 7:51 AM, Jules Bean [EMAIL PROTECTED] wrote: class Shape a where { intersect :: Shape b = a - b - Bool } Shouldn't this be class Shape a where whatever class (Shape a, Shape b) = Intersectable a b where intersect :: a - b - Bool With your definition I don't

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread C.M.Brown
If however, you *really* want to keep your shapes as being seperate types, then you'll want to invoke the class system (note, not the same as OO classes). class Shape a where area :: a - Int newtype Circle = C Int instance Shape Circle where area (C r) = pi * r^2 newtype

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Tillmann Rendel
Felipe Lessa wrote: class Shape a where whatever class (Shape a, Shape b) = Intersectable a b where intersect :: a - b - Bool This looks nice at first sight, but is it usefull in practice? I can somehow express the type any shape wich is intersectable with a given other shape,

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Lutz Donnerhacke
* Tillmann Rendel wrote: My conclusion: To make Haskell a better OO language Haskell is not an OO language and never should be. (Since it's not the goal of Haskell to be any OO language at all this may not be a problem) Ack. ___ Haskell-Cafe

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread Sterling Clover
Don't think the Haskell's Overlooked Object System paper has been posted to this thread yet: http://homepages.cwi.nl/~ralf/OOHaskell/paper.pdf --s On 12/18/07, Lutz Donnerhacke [EMAIL PROTECTED] wrote: * Tillmann Rendel wrote: My conclusion: To make Haskell a better OO language Haskell

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Thomas Davie
On 17 Dec 2007, at 10:46, Nicholls, Mark wrote: I can obviously at a later date add a new class Triangle, and not have to touch any of the above code…. Yes, and you can indeed do a similar thing in Haskell. The natural thing to do here would be to define a type Shape... data Shape =

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Ketil Malde
Nicholls, Mark [EMAIL PROTECTED] writes: After many years of OOP though my brain is wired up to construct software in that ?pattern??.a problem for me at the moment is I cannot see how to construct programs in an OO style in Haskell?.I know this is probably not the way to approach it?but I

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
December 2007 11:04 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions. On 17 Dec 2007, at 10:46, Nicholls, Mark wrote: I can obviously at a later date add a new class Triangle, and not have to touch any of the above code

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Thomas Davie
On 17 Dec 2007, at 11:14, Nicholls, Mark wrote: OK I'll have to digest this and mess about a bitbut can I make an observation at this point If I define Shape like data Shape = Circle Int | Rectangle Int Int | Square Int Isn't this now closed...i.e. the

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions. On 17 Dec 2007, at 10:46, Nicholls, Mark wrote: I can obviously at a later date add a new class Triangle, and not have to touch any of the above code Yes, and you can indeed do a similar

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Stuart Cook
On Dec 17, 2007 10:47 PM, Nicholls, Mark [EMAIL PROTECTED] wrote: The constructor of a newtype must have exactly one field but `R' has two In the newtype declaration for `Rectangle' It doesn't like newtype Rectangle = R Int Int A newtype can only have one constructor, with one argument,

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Jed Brown
On 17 Dec 2007, [EMAIL PROTECTED] wrote: Ooo The constructor of a newtype must have exactly one field but `R' has two In the newtype declaration for `Rectangle' It doesn't like newtype Rectangle = R Int Int You want data Rectangle = R Int Int A newtype declaration will be completely

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
Ok... Thanks I need to revisit data and newtype to work out what the difference is I think. -Original Message- From: Jed Brown [mailto:[EMAIL PROTECTED] On Behalf Of Jed Brown Sent: 17 December 2007 12:04 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] OOP'er

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Thomas Davie
On 17 Dec 2007, at 12:22, Nicholls, Mark wrote: Ok... Thanks I need to revisit data and newtype to work out what the difference is I think. Beware in doing so -- type, and newtype are not the same either. type creates a type synonim. That is, if I were to declare type Jam = Int then

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
. -Original Message- From: Thomas Davie [mailto:[EMAIL PROTECTED] Sent: 17 December 2007 12:35 To: Nicholls, Mark Cc: Haskell Cafe Subject: Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions. On 17 Dec 2007, at 12:22, Nicholls, Mark wrote: Ok... Thanks I need to revisit data

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Henning Thielemann
On Mon, 17 Dec 2007, Nicholls, Mark wrote: After many years of OOP though my brain is wired up to construct software in that 'pattern'a problem for me at the moment is I cannot see how to construct programs in an OO style in HaskellI know this is probably not the way to approach

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
Ahhh I'll give it a read. thanks -Original Message- From: Henning Thielemann [mailto:[EMAIL PROTECTED] Sent: 17 December 2007 13:05 To: Nicholls, Mark Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions. On Mon, 17 Dec 2007, Nicholls

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Brent Yorgey
On Dec 17, 2007 8:04 AM, Nicholls, Mark [EMAIL PROTECTED] wrote: No that's fineits all as clear as mud!..but that's not your fault. To recap... type introduces a synonym for another type, no new type is createdit's for readabilities sake. Newtype introduces an isomorphic copy

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Nicholls, Mark
: [Haskell-cafe] OOP'er with (hopefully) trivial questions. On Dec 17, 2007 8:04 AM, Nicholls, Mark [EMAIL PROTECTED] wrote: No that's fineits all as clear as mud!..but that's not your fault. To recap... type introduces a synonym for another type, no new type is createdit's

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Wolfgang Jeltsch
Am Montag, 17. Dezember 2007 13:04 schrieb Jed Brown: […] When your type only has one constructor, newtype is preferred over data, but they are semantically equivalent. They are *not* semantically equivalent, as has already been said more or less. data adds an extra level of indirection.

RE: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Peter Verswyvelen
: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Wolfgang Jeltsch Sent: Monday, December 17, 2007 5:39 PM To: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions. Am Montag, 17. Dezember 2007 13:04 schrieb Jed Brown: […] When your type only

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Ketil Malde
Thomas Davie [EMAIL PROTECTED] writes: Yes, and you can indeed do a similar thing in Haskell. The natural thing to do here would be to define a type Shape... data Shape = Circle Int | Rectangle Int Int | Square Int If however, you *really* want to keep your shapes

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Jules Bean
Peter Verswyvelen wrote: Very interesting, I did not know that! I thought newtype was an optimization of data, and that newtype was bad terminology. But if newtype is just a wrapper around a type, then the name is choosen well. I'm a bit confused why then one needs a data-constructor-like

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Evan Laforge
A newtype can only have one constructor, with one argument, and is essentially a wrapper for that argument type. In the general case, you want to use data instead of newtype: data Rectangle = R Int Int I'm sure there's a trivial explanation for this, but here's something that I've always

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Evan Laforge
I'm sure there's a trivial explanation for this, but here's something that I've always kind of wondered about: Given a single constructor type like data X = X A B C can't that be transformed into newtype X = X (A, B, C)? There must be some difference, because if there weren't we could

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Tim Chevalier
On 12/17/07, Evan Laforge [EMAIL PROTECTED] wrote: I'm sure there's a trivial explanation for this, but here's something that I've always kind of wondered about: Given a single constructor type like data X = X A B C can't that be transformed into newtype X = X (A, B, C)? There must be some

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Tim Chevalier
On 12/17/07, Evan Laforge [EMAIL PROTECTED] wrote: Oops, nevermind, I just saw the other thread and link to http://www.haskell.org/haskellwiki/Newtype. Ok, so that seems like a pretty subtle diffenence... I'm assuming the rationale behind differentiating between a single constructor data and

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Wolfgang Jeltsch
Am Montag, 17. Dezember 2007 19:26 schrieb Tim Chevalier: On 12/17/07, Evan Laforge [EMAIL PROTECTED] wrote: I'm sure there's a trivial explanation for this, but here's something that I've always kind of wondered about: Given a single constructor type like data X = X A B C can't that be

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Tim Chevalier
On 12/17/07, Wolfgang Jeltsch [EMAIL PROTECTED] wrote: This is not a generalization of what you talked about. Why should the tuple type be unboxed? Tuple types are boxed, meaning there is a difference between _|_ and (_|_,…,_|_). If you write newtype X = X (A, B, C) then X doesn't

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Miguel Mitrofanov
There's a third way, too, and I haven't seen anybody mention it yet I've noticed it, but there are some problems with this representation, so I decided not to mention it. It's OK as far as we don't want functions working on two areas - I don't see, how we can implement, say, intersect ::

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Evan Laforge
I interpreted Evan's question as why can't you have newtypes with multiple fields? -- i.e., newtype X = X A B C -- and that's the question I was answering. But maybe I misunderstood. Well, the question was both, and strictness answers both. Thanks for the clarification. I should have

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Derek Elkins
On Mon, 2007-12-17 at 22:12 +0300, Miguel Mitrofanov wrote: There's a third way, too, and I haven't seen anybody mention it yet I've noticed it, but there are some problems with this representation, so I decided not to mention it. It's OK as far as we don't want functions working on two

Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-17 Thread Ketil Malde
Miguel Mitrofanov [EMAIL PROTECTED] writes: I've noticed it, but there are some problems with this representation, so I decided not to mention it. It's OK as far as we don't want functions working on two areas - I don't see, how we can implement, say, intersect :: Shape - Shape - Bool in this