Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Equivalence of Inheritance (Antoine Latter)
2. Type unions (Russ Abbott)
3. Re: Type unions (Tobias Brandt)
4. Re: Equivalence of Inheritance (Russ Abbott)
5. Re: Equivalence of Inheritance (Antoine Latter)
6. Re: Type unions (Russ Abbott)
7. Re: Equivalence of Inheritance (Russ Abbott)
----------------------------------------------------------------------
Message: 1
Date: Tue, 14 Dec 2010 13:58:28 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: [email protected]
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <[email protected]> wrote:
> If gender is a field in a Person type, then a Person must have both an
> ovaryCondition and a prostateCondition. ?That seems awkward.
> Regarding
> ?? ? class Person p where
> I started down that path but got completely fouled up.
How did this get fouled up? Every class declaration must take
arguments - here, 'p' is the argument for the class.
Thanks,
Antoine
------------------------------
Message: 2
Date: Tue, 14 Dec 2010 12:09:05 -0800
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Type unions
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Is there a way to get this to work?
data A = Aconstructor Int
data B = Bconstructor Int
data AorB = A | B
f :: Int -> AorB
f x
| even x = Aconstructor x
| otherwise = Bconstructor x
I get this diagnostic.
Couldn't match expected type `AorB' against inferred type `A'
Since AorB is A or B, why is this not permitted?
If instead I write
data AorB = Aconstructor Int | Bconstructor Int
everything works out ok. But what if I want separate types for A and B?
Thanks,
*
-- Russ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/03c2b600/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 14 Dec 2010 21:14:50 +0100
From: Tobias Brandt <[email protected]>
Subject: Re: [Haskell-beginners] Type unions
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Use Either A B from Data.Either:
http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Either.html#t%3AEither
On 14 December 2010 21:09, Russ Abbott <[email protected]> wrote:
> Is there a way to get this to work?
>
> data A = Aconstructor Int
> data B = Bconstructor Int
> data AorB = A | B
> f :: Int -> AorB
> f x
> ??| even x ? ? = Aconstructor x
> ??| otherwise = Bconstructor x
>
> ?I get this diagnostic.
>
> Couldn't match expected type `AorB' against inferred type `A'
>
> Since AorB is A or B, why is this not permitted?
> If instead I write
>
> data AorB = Aconstructor Int | Bconstructor Int
>
> everything works out ok. But what if I want separate types for A and B?
> Thanks,
> -- Russ
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
------------------------------
Message: 4
Date: Tue, 14 Dec 2010 12:12:29 -0800
From: Russ Abbott <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: Antoine Latter <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
What got fouled up is all the adjustments I had to make to the other
declarations.
Can you complete the example so that it compiles using
class Person p where ...
I'd very much like to see an example that actually compiles.
Thanks.
*
-- Russ *
On Tue, Dec 14, 2010 at 11:58 AM, Antoine Latter <[email protected]> wrote:
> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <[email protected]>
> wrote:
> > If gender is a field in a Person type, then a Person must have both an
> > ovaryCondition and a prostateCondition. That seems awkward.
> > Regarding
> > class Person p where
> > I started down that path but got completely fouled up.
>
> How did this get fouled up? Every class declaration must take
> arguments - here, 'p' is the argument for the class.
>
> Thanks,
> Antoine
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/e7ff43ec/attachment-0001.htm>
------------------------------
Message: 5
Date: Tue, 14 Dec 2010 14:18:52 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: [email protected]
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Sorry, I really don't know enough about what you're after to attempt that.
But you'll need to change you're signatures of the form:
> function :: Person -> Foo
to something of the form:
> function :: Person p => p -> Foo
Because again, a type class can not be used as a type.
Antoine
On Tue, Dec 14, 2010 at 2:12 PM, Russ Abbott <[email protected]> wrote:
> What got fouled up is all the adjustments I had to make to the other
> declarations.
> Can you?complete?the example so that it compiles using
>
> class Person p where ...
>
> I'd very much like to see an example that actually compiles.
>
> Thanks.
> -- Russ
>
> On Tue, Dec 14, 2010 at 11:58 AM, Antoine Latter <[email protected]> wrote:
>>
>> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <[email protected]>
>> wrote:
>> > If gender is a field in a Person type, then a Person must have both an
>> > ovaryCondition and a prostateCondition. ?That seems awkward.
>> > Regarding
>> > ?? ? class Person p where
>> > I started down that path but got completely fouled up.
>>
>> How did this get fouled up? Every class declaration must take
>> arguments - here, 'p' is the argument for the class.
>>
>> Thanks,
>> Antoine
>
>
------------------------------
Message: 6
Date: Tue, 14 Dec 2010 12:26:21 -0800
From: Russ Abbott <[email protected]>
Subject: Re: [Haskell-beginners] Type unions
To: Tobias Brandt <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Isn't "Either" the same thing as AorB in
data AorB = Aconstructor Int | Bconstructor Int
I want two separate types A and B along with a third type which is their
Union. Is that not possible?
In my actual case, I have more than two types. So I would like a way to
take the union of an arbitrarily number of types.
data Union = A1 | A2 | ...
where each of A1, A2, ... has its own data declaration.
*
-- Russ *
On Tue, Dec 14, 2010 at 12:14 PM, Tobias Brandt
<[email protected]>wrote:
> data AorB = Aconstructor Int | Bconstructor Int
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/e79a75d5/attachment-0001.htm>
------------------------------
Message: 7
Date: Tue, 14 Dec 2010 12:27:57 -0800
From: Russ Abbott <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: Antoine Latter <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
What I'm after is a version of my example that compiles. Can you make one?
*
-- Russ *
*
*
On Tue, Dec 14, 2010 at 12:18 PM, Antoine Latter <[email protected]> wrote:
> Sorry, I really don't know enough about what you're after to attempt that.
>
> But you'll need to change you're signatures of the form:
>
> > function :: Person -> Foo
>
> to something of the form:
>
> > function :: Person p => p -> Foo
>
> Because again, a type class can not be used as a type.
>
> Antoine
>
> On Tue, Dec 14, 2010 at 2:12 PM, Russ Abbott <[email protected]>
> wrote:
> > What got fouled up is all the adjustments I had to make to the other
> > declarations.
> > Can you complete the example so that it compiles using
> >
> > class Person p where ...
> >
> > I'd very much like to see an example that actually compiles.
> >
> > Thanks.
> > -- Russ
> >
> > On Tue, Dec 14, 2010 at 11:58 AM, Antoine Latter <[email protected]>
> wrote:
> >>
> >> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <[email protected]>
> >> wrote:
> >> > If gender is a field in a Person type, then a Person must have both an
> >> > ovaryCondition and a prostateCondition. That seems awkward.
> >> > Regarding
> >> > class Person p where
> >> > I started down that path but got completely fouled up.
> >>
> >> How did this get fouled up? Every class declaration must take
> >> arguments - here, 'p' is the argument for the class.
> >>
> >> Thanks,
> >> Antoine
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/b87e050e/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 25
*****************************************