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:  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 <aslat...@gmail.com>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: russ.abb...@gmail.com
Cc: beginners@haskell.org
Message-ID:
        <aanlktik9ho7qvgvzjm1prw8w5_=qxwe74p7olhkns...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <russ.abb...@gmail.com> 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 <russ.abb...@gmail.com>
Subject: [Haskell-beginners] Type unions
To: beginners <beginners@haskell.org>
Message-ID:
        <aanlktikww9uaibc9noyjaxd-b6gcqyz2m0weozddb...@mail.gmail.com>
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 <tob.bra...@googlemail.com>
Subject: Re: [Haskell-beginners] Type unions
To: russ.abb...@gmail.com
Cc: beginners <beginners@haskell.org>
Message-ID:
        <aanlkti=hj9zpwtik+cmgtvg0_vgka8dhenwycmois...@mail.gmail.com>
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 <russ.abb...@gmail.com> 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
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



------------------------------

Message: 4
Date: Tue, 14 Dec 2010 12:12:29 -0800
From: Russ Abbott <russ.abb...@gmail.com>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: Antoine Latter <aslat...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlkti=tkjd8rxgg6mom30xhv44gamxslff-0k3tk...@mail.gmail.com>
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 <aslat...@gmail.com> wrote:

> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <russ.abb...@gmail.com>
> 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 <aslat...@gmail.com>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: russ.abb...@gmail.com
Cc: beginners@haskell.org
Message-ID:
        <aanlktikj-lhwvhswwcevqvqbt+es-itu_zhqwh6of...@mail.gmail.com>
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 <russ.abb...@gmail.com> 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 <aslat...@gmail.com> wrote:
>>
>> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <russ.abb...@gmail.com>
>> 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 <russ.abb...@gmail.com>
Subject: Re: [Haskell-beginners] Type unions
To: Tobias Brandt <tob.bra...@googlemail.com>
Cc: beginners <beginners@haskell.org>
Message-ID:
        <aanlktikmjhoaj3rngkguez_m7l9z2msvy0c0fwp_d...@mail.gmail.com>
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
<tob.bra...@googlemail.com>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 <russ.abb...@gmail.com>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: Antoine Latter <aslat...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktimttbetvmsdh7c_fkr3msashgcnk9nqgwsz-...@mail.gmail.com>
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 <aslat...@gmail.com> 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 <russ.abb...@gmail.com>
> 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 <aslat...@gmail.com>
> wrote:
> >>
> >> On Tue, Dec 14, 2010 at 1:52 PM, Russ Abbott <russ.abb...@gmail.com>
> >> 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
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 30, Issue 25
*****************************************

Reply via email to