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 (Russ Abbott)
2. Re: GUI library for beginners? (Henk-Jan van Tuyl)
3. Re: Type unions (Ozgur Akgun)
4. Re: Equivalence of Inheritance (Michael Katelman)
----------------------------------------------------------------------
Message: 1
Date: Tue, 14 Dec 2010 13:53:57 -0800
From: Russ Abbott <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: Michael Katelman <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Ozgur pointed out this notition p...@man{}. What I would like is something
like this.
type Man = per...@man{}
type MensGroup = [Man]
*
-- Russ *
On Tue, Dec 14, 2010 at 1:45 PM, Michael Katelman <[email protected]> wrote:
> Without going too exotic, I see two choices. Keeping the single type
> Person makes what you are asking for, as far as I know, impossible
> (dependent types). For human readability you could consider
>
> type MensGroup = [Person]
> type WomensGroup = [Person]
>
> If you split Person into two types, Man and Woman, there are
> repercussions for the aggregate group type
>
> type Group = [Either Man Woman]
>
> -Mike
>
>
> On Tue, Dec 14, 2010 at 3:30 PM, Russ Abbott <[email protected]>
> wrote:
> > Now that this is straightened out, I went back to what I was doing in the
> > first place and realized that I haven't solved my problem.
> > Given
> >
> > data Person =
> > Man {name :: String, age :: Int, prostateCondition :: Condition}
> > | Woman {name :: String, age :: Int, ovaryCondition :: Condition}
> >
> > I'd like to define something like this.
> >
> > type MensGroup = [Man]
> >
> > Is there a way to do something like that?
> > -- Russ
> >
> >
> > On Tue, Dec 14, 2010 at 1:06 PM, Russ Abbott <[email protected]>
> wrote:
> >>
> >> That's good. (It's more or less the way I was doing it.) What I wanted
> to
> >> avoid was this.
> >>
> >> getGenderSpecificCondition ( Man _ _ cond) = cond
> >> getGenderSpecificCondition (Woman _ _ cond) = cond
> >>
> >> I know it seems like a small thing, but I would like to be able to write
> >> it like this.
> >>
> >> getGenderSpecificCondition p
> >> | p == (Man _ _ cond) = cond
> >> | p == (Woman _ _ cond) = cond
> >>
> >> But that's not legal syntax. A pattern can't appear in that context.
> But
> >> this does the job.
> >>
> >> getGenderSpecificCondition :: Person -> Condition
> >> getGenderSpecificCondition p
> >> | isMan p = prostateCondition p
> >> | isWoman p = ovaryCondition p
> >>
> >> isMan ( Man _ _ cond) = True
> >> isMan _ = False
> >> isWoman (Woman _ _ cond) = True
> >> isWoman _ = False
> >>
> >> That works! prostateCondition and ovaryCondition are both defined on
> >> Person. (I'm surprised to see that.)
> >>
> >> *Person> Group [Man "Harry" 32 OK, Woman "Sally" 29 Good]
> >> Harry(32, OK)
> >> Sally(29, Good)
> >>
> >> Also
> >>
> >> *Person> prostateCondition (Woman "Sally" 29 Good)
> >> *** Exception: No match in record selector prostateCondition
> >> *Person> prostateCondition (Man "Harry" 29 Good)
> >> Good
> >>
> >> -- Russ
> >>
> >>
> >> On Tue, Dec 14, 2010 at 12:31 PM, Michael Katelman <[email protected]>
> >> wrote:
> >>>
> >>> Perhaps this?
> >>>
> >>> https://gist.github.com/741048
> >>>
> >>> -Mike
> >>>
> >>> On Tue, Dec 14, 2010 at 2:27 PM, Russ Abbott <[email protected]>
> >>> wrote:
> >>> > 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
> >>> >> >
> >>> >> >
> >>> >
> >>> >
> >>> > _______________________________________________
> >>> > Beginners mailing list
> >>> > [email protected]
> >>> > http://www.haskell.org/mailman/listinfo/beginners
> >>> >
> >>> >
> >>
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/436ef2fb/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 14 Dec 2010 23:12:24 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] GUI library for beginners?
To: [email protected], "Venanzio Capretta" <[email protected]>,
"Henk-Jan van Tuyl" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Tue, 14 Dec 2010 16:26:56 +0100, Henk-Jan van Tuyl <[email protected]>
wrote:
> On Tue, 14 Dec 2010 10:16:40 +0100, Venanzio Capretta
> <[email protected]> wrote:
>
>> Next I tried with wxHaskell, but unfortunately it doesn't install on
>> Ubuntu (I checked on the mailing list: other people had the same
>> problem and I don't understand the solution).
>
> To get wxHaskell working on Ubuntu (and probably on most other
> platforms), you need to install the g++ compiler, see:
> ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.5.1/
>
> I guess you need the file gcc-g++-4.5.1.tar.gz
>
> Regards,
> Henk-Jan van Tuyl
>
>
It is probably better to give the command:
sudo apt-get install g++
I updated the page
http://www.haskell.org/haskellwiki/WxHaskell/Linux
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
------------------------------
Message: 3
Date: Tue, 14 Dec 2010 22:15:06 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Type unions
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
This reminds me of an old thread started by, well me :)
http://www.haskell.org/pipermail/haskell-cafe/2010-March/074805.html (sorry
for the typos)
It is not an especially enlightening thread, but contains some nice
references.
HTH,
On 14 December 2010 20: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 *
>
>
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/ce023073/attachment-0001.htm>
------------------------------
Message: 4
Date: Tue, 14 Dec 2010 16:20:19 -0600
From: Michael Katelman <[email protected]>
Subject: Re: [Haskell-beginners] Equivalence of Inheritance
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I often find myself in a similar predicament, become frustrated, and
after I've wasted a lot time ultimately decide that I'm making perfect
the enemy of good.
One possible option that hasn't been mentioned is to try and enforce
safety at the module boundary, perhaps by making MensGroup a newtype
and instead of exporting the constructor to export some other function
that ensures only men wind up in a MensGroup. Sounds cumbersome to me,
though.
-Mike
On Tue, Dec 14, 2010 at 3:53 PM, Russ Abbott <[email protected]> wrote:
> Ozgur pointed out this notition p...@man{}. ?What I would like is something
> like this.
> type Man = per...@man{}
> type MensGroup = [Man]
>
> -- Russ
>
>
> On Tue, Dec 14, 2010 at 1:45 PM, Michael Katelman <[email protected]> wrote:
>>
>> Without going too exotic, I see two choices. Keeping the single type
>> Person makes what you are asking for, as far as I know, impossible
>> (dependent types). For human readability you could consider
>>
>> type MensGroup = [Person]
>> type WomensGroup = [Person]
>>
>> If you split Person into two types, Man and Woman, there are
>> repercussions for the aggregate group type
>>
>> type Group = [Either Man Woman]
>>
>> -Mike
>>
>>
>> On Tue, Dec 14, 2010 at 3:30 PM, Russ Abbott <[email protected]>
>> wrote:
>> > Now that this is straightened out, I went back to what I was doing in
>> > the
>> > first place and?realized?that I haven't solved my problem.
>> > Given
>> >
>> > data Person =
>> > ?? ? ?Man {name :: String, age :: Int, prostateCondition :: Condition}
>> > ??| Woman {name :: String, age :: Int, ovaryCondition ? ?:: Condition}
>> >
>> > I'd like to define something like this.
>> >
>> > type MensGroup = [Man]
>> >
>> > Is there a way to do something like that?
>> > -- Russ
>> >
>> >
>> > On Tue, Dec 14, 2010 at 1:06 PM, Russ Abbott <[email protected]>
>> > wrote:
>> >>
>> >> That's good. (It's more or less the way I was doing it.) ?What I wanted
>> >> to
>> >> avoid was this.
>> >>
>> >> getGenderSpecificCondition ( ?Man _ _ cond) = cond
>> >> getGenderSpecificCondition (Woman _ _ cond) = cond
>> >>
>> >> I know it seems like a small thing, but I would like to be able to
>> >> write
>> >> it like this.
>> >>
>> >> getGenderSpecificCondition p
>> >> ?? | p == (Man _ _ cond) = cond
>> >> ?? | p == (Woman _ _ cond) = cond
>> >>
>> >> But that's not legal syntax. ?A pattern can't appear in that context.
>> >> But
>> >> this does the job.
>> >>
>> >> getGenderSpecificCondition :: Person -> Condition
>> >> getGenderSpecificCondition p
>> >> ?? | isMan p = prostateCondition p
>> >> ?? | isWoman p = ovaryCondition p
>> >>
>> >> isMan ( ? ? Man _ _ cond) = True
>> >> isMan _ = False
>> >> isWoman (Woman _ _ cond) = True
>> >> isWoman _ = False
>> >>
>> >> That works! prostateCondition and ovaryCondition are both defined on
>> >> Person. (I'm surprised to see that.)
>> >>
>> >> *Person> Group [Man "Harry" 32 OK, Woman "Sally" 29 Good]
>> >> Harry(32, OK)
>> >> Sally(29, Good)
>> >>
>> >> Also
>> >>
>> >> *Person> prostateCondition (Woman "Sally" 29 Good)
>> >> *** Exception: No match in record selector prostateCondition
>> >> *Person> prostateCondition (Man "Harry" 29 Good)
>> >> Good
>> >>
>> >> -- Russ
>> >>
>> >>
>> >> On Tue, Dec 14, 2010 at 12:31 PM, Michael Katelman <[email protected]>
>> >> wrote:
>> >>>
>> >>> Perhaps this?
>> >>>
>> >>> https://gist.github.com/741048
>> >>>
>> >>> -Mike
>> >>>
>> >>> On Tue, Dec 14, 2010 at 2:27 PM, Russ Abbott <[email protected]>
>> >>> wrote:
>> >>> > 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
>> >>> >> >
>> >>> >> >
>> >>> >
>> >>> >
>> >>> > _______________________________________________
>> >>> > Beginners mailing list
>> >>> > [email protected]
>> >>> > http://www.haskell.org/mailman/listinfo/beginners
>> >>> >
>> >>> >
>> >>
>> >
>> >
>
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 30
*****************************************