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:  Typeclasses and "inheritance" (Chadda? Fouch?)
   2. Re:  Typeclasses and "inheritance" (Patrick LeBoutillier)
   3. Re:  Typeclasses and "inheritance" (Isaac Dupree)
   4.  haskell variables - or not (Duke Normandin)
   5. Re:  haskell variables - or not (Thomas Friedrich)
   6. Re:  haskell variables - or not (Thomas Davie)
   7. Re:  haskell variables - or not (Kyle Murphy)
   8.  Count how often a menu has been selected (Bernhard Lehnert)


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

Message: 1
Date: Fri, 24 Jul 2009 20:27:35 +0200
From: Chadda? Fouch? <chaddai.fou...@gmail.com>
Subject: Re: [Haskell-beginners] Typeclasses and "inheritance"
To: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <e9350eaf0907241127kb3a257bt853d519c83e63...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Fri, Jul 24, 2009 at 6:16 PM, Patrick
LeBoutillier<patrick.leboutill...@gmail.com> wrote:
> In the declaration of the class IPAddr, is there any way to force that the
> IPHost and IPMask types are made up from the same IPBits type? Basically I
> would like the compiler to enforce that Word (Host a) and Word (Mask a) be
> the same type for a specific instance of IPAddr.

Unfortunately, this has not been implemented yet (in 6.10), though it
should be in a future version of GHC (pretty soon probably), you'll
then be able to write :

> class (IPHost (Host a), IPMask (Mask a), Word (Host a) ~ Word (Mask a)) => 
> IPAddr a where

but for now you must content yourself with adding it to the function context :

>   -- Takes an IPAddr and returns another one describing the network
>   subnet :: (Word (Host a) ~ Word (Mask a)) => a -> a
>   subnet a = let m = mask a
>                  h = host a
>              in makeIPAddr (fromBits $ (bits h) .&. (bits m)) $ m

Note that I didn't put a IPAddr context since in your code subnet is a
method of this class (with a default implementation), if this wasn't
your intention you should correct the indentation.

-- 
Jedaï


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

Message: 2
Date: Fri, 24 Jul 2009 15:03:34 -0400
From: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Subject: Re: [Haskell-beginners] Typeclasses and "inheritance"
To: Chadda? Fouch? <chaddai.fou...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <b217a64f0907241203t24ea9929l682fc226fee5...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

>
> >   -- Takes an IPAddr and returns another one describing the network
> >   subnet :: (Word (Host a) ~ Word (Mask a)) => a -> a
> >   subnet a = let m = mask a
> >                  h = host a
> >              in makeIPAddr (fromBits $ (bits h) .&. (bits m)) $ m


Excellent!


> Note that I didn't put a IPAddr context since in your code subnet is a
> method of this class (with a default implementation), if this wasn't
> your intention you should correct the indentation.


You are right, the context was not necessary. The function is in fact a
default implementation.

BTW: Does what I'm trying to do make any sense at all? Does anyone know of a
better/simpler way to do this (i.e making most of these computations
independant of the exact underlying type)?


Anyways, thanks a lot for your help,

Patrick



>
> --
> Jedaï
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090724/e814bf4d/attachment-0001.html

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

Message: 3
Date: Fri, 24 Jul 2009 15:36:19 -0400
From: Isaac Dupree <m...@isaac.cedarswampstudios.org>
Subject: Re: [Haskell-beginners] Typeclasses and "inheritance"
To: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <4a6a0d33.10...@isaac.cedarswampstudios.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Patrick LeBoutillier wrote:
> BTW: Does what I'm trying to do make any sense at all? Does anyone know of a
> better/simpler way to do this (i.e making most of these computations
> independant of the exact underlying type)?

Actually, I would try to mostly avoid typeclasses.  If you want to 
change the representation sometime, that's still possible if you have 
abstraction!

maybe like
data IPAddr n = IPAddr n n
where typically n would be Word32 or Word128(does that exist?), and a 
polymorphic function doing math on it might use a (Num n) => context.

Actually you might sometimes need to know what kind of address it is. 
Then I guess we could have
data IPVersion = V4 | V6
class IPAddrRepr n where ipVersion :: n -> IPVersion
instance IPAddrRepr Word32 where ipVersion _ = V4
instance IPAddrRepr Word128 where ipVersion _ = V6
-- and for convenience, maybe,
instance (IPAddrRepr n) => IPAddrRepr (IPAddr n)
   where ipVersion (IPAddr n _) = ipVersion n

Alternatively I have an inkling that you could play with GADTs.  But the 
basic Haskell type system is surprisingly powerful itself!  There might 
be a way to write what you want without extensions.  It depends on 
exactly what you're trying to do.  For some purposes we might need to 
change/add to have a
data IPVersioned = V4 (IPAddr Word32) | V6 (IPAddr Word128)

-Isaac


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

Message: 4
Date: Fri, 24 Jul 2009 22:25:59 -0600 (MDT)
From: Duke Normandin <dukeofp...@ml1.net>
Subject: [Haskell-beginners] haskell variables - or not
To: beginners@haskell.org
Message-ID:
        <alpine.osx.2.00.0907242200080.5...@q75-154-104-166.noufvn.gryhf.arg>
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hello....

I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL, newLISP. I'm
using "YAHT.pdf" as an intro to Haskell. Here's a quote:

[quote]
... if you have a value x, you must not think of x as a register, a
memory location or anything else of that nature. x is simply a name, just as
Hal  is my name. You cannot arbitrarily decide to store a different person in
my name any more than you can arbitrarily decide to store a different value in
x. This means that code that might look like the following C code is invalid
(and has no counterpart) in Haskell:

int x = 5;
[/quote]

So is fair to say that an expression in Haskell like:

x = 5

is more like a constant in imperative languages - say Perl? E.g.

 use constant SECONDS_PER_DAY => 86400;
--
duke


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

Message: 5
Date: Sat, 25 Jul 2009 00:32:43 -0400
From: Thomas Friedrich <i...@suud.de>
Subject: Re: [Haskell-beginners] haskell variables - or not
To: beginners@haskell.org
Message-ID: <4a6a8aeb.1020...@suud.de>
Content-Type: text/plain; charset=ISO-8859-1

Duke Normandin wrote:
> Hello....
>
> I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL, newLISP. I'm
> using "YAHT.pdf" as an intro to Haskell. Here's a quote:
>
> [quote]
> ... if you have a value x, you must not think of x as a register, a
> memory location or anything else of that nature. x is simply a name, just as
> Hal  is my name. You cannot arbitrarily decide to store a different person in
> my name any more than you can arbitrarily decide to store a different value in
> x. This means that code that might look like the following C code is invalid
> (and has no counterpart) in Haskell:
>
> int x = 5;
> [/quote]
>
> So is fair to say that an expression in Haskell like:
>
> x = 5
>
> is more like a constant in imperative languages - say Perl? E.g.
>
>  use constant SECONDS_PER_DAY => 86400;
> --
> duke
>   

No.  Think of

x :: Int
x = 5

more in terms of an expression rather than a variable.  If you evaluate
the expression x, say you would like to print its evaluation on the
screen, then x is evaluated to the value 5.  As the name of an
expression needs to be unique in order to refer to it anywhere else in
the program, you cannot have something like

x :: Int
x = 53

somewhere else in your code.  Because then the expression x would be
ambiguous.

You will get the idea in a couple of days.  I am sure.

Best,
Thomas


> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>   



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

Message: 6
Date: Sat, 25 Jul 2009 09:56:04 +0200
From: Thomas Davie <tom.da...@gmail.com>
Subject: Re: [Haskell-beginners] haskell variables - or not
To: Duke Normandin <dukeofp...@ml1.net>
Cc: beginners@haskell.org
Message-ID: <ce39da26-b618-4597-9b9b-94cead0e0...@gmail.com>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


On 25 Jul 2009, at 06:25, Duke Normandin wrote:

> Hello....
>
> I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL,  
> newLISP. I'm
> using "YAHT.pdf" as an intro to Haskell. Here's a quote:
>
> [quote]
> ... if you have a value x, you must not think of x as a register, a
> memory location or anything else of that nature. x is simply a name,  
> just as
> Hal  is my name. You cannot arbitrarily decide to store a different  
> person in
> my name any more than you can arbitrarily decide to store a  
> different value in
> x. This means that code that might look like the following C code is  
> invalid
> (and has no counterpart) in Haskell:
>
> int x = 5;
> [/quote]
>
> So is fair to say that an expression in Haskell like:
>
> x = 5
>
> is more like a constant in imperative languages - say Perl? E.g.
>
> use constant SECONDS_PER_DAY => 86400;

x is indeed a constant in this case.  The = sign in Haskell is used  
not for "assignment" as in most imperative programming languages, but  
instead for "binding" as in most mathematics.  It says "x is equal to  
5", "x always has been equal to 5", "x will always be equal to 5".   
The reason why these are still called variables is from when they are  
used as arguments to functions:

f y = y + 2

Here, we are "binding" f.  f always was, will be and is the function  
which adds two to its argument, but it's argument varies depending on  
the call, and thus is a variable.

Hope that helps.

Bob


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

Message: 7
Date: Sat, 25 Jul 2009 06:21:31 -0400
From: Kyle Murphy <orc...@gmail.com>
Subject: Re: [Haskell-beginners] haskell variables - or not
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID: <0ce43a15-9b65-466a-881f-e2636b839...@gmail.com>
Content-Type: text/plain;       charset=us-ascii;       format=flowed;  
delsp=yes

Well, the short answer is sort of. The long answer is that you can't  
really have variables declared outside of a function definition. When  
you do something like:
x = 5
what you're really doing is declaring a new function x that takes no  
arguments and returns the constant 5.

On Jul 25, 2009, at 12:25 AM, Duke Normandin <dukeofp...@ml1.net> wrote:

> Hello....
>
> I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL,  
> newLISP. I'm
> using "YAHT.pdf" as an intro to Haskell. Here's a quote:
>
> [quote]
> ... if you have a value x, you must not think of x as a register, a
> memory location or anything else of that nature. x is simply a name,  
> just as
> Hal  is my name. You cannot arbitrarily decide to store a different  
> person in
> my name any more than you can arbitrarily decide to store a  
> different value in
> x. This means that code that might look like the following C code is  
> invalid
> (and has no counterpart) in Haskell:
>
> int x = 5;
> [/quote]
>
> So is fair to say that an expression in Haskell like:
>
> x = 5
>
> is more like a constant in imperative languages - say Perl? E.g.
>
> use constant SECONDS_PER_DAY => 86400;
> --
> duke
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


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

Message: 8
Date: Sat, 25 Jul 2009 13:10:02 +0200
From: Bernhard Lehnert <b.lehn...@gmx.de>
Subject: [Haskell-beginners] Count how often a menu has been selected
To: beginners@haskell.org
Message-ID: <1248520202.29584.13.ca...@sol>
Content-Type: text/plain

Hi list,

using gtk2hs I would like to count how often a Menu has been selected
(well, not really, but it kind of breaks down to this):


    let a = 0
    onActivateLeaf menuAddOne $ do
        let a = a+1
        print a


This leads to a stack overflow. Obviously a=a+1 is iterated over and
over again. But how can I add something each time the menu is activated?
(Actually I want to open a FileDialog and add the contents of a file to
a list but for now, counting would be great).

Thanks to everyone for reading,
Bernhard





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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 13, Issue 15
*****************************************

Reply via email to