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
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
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
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
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
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
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,
* 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
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
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 =
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
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
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
: 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
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,
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
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
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
.
-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
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
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
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
: [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
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.
: [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
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
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
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
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
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
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
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
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
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 ::
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
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
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
37 matches
Mail list logo