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: print all days of calendar (Daniel Fischer)
2. Re: Enum for natural numbers (Daniel Fischer)
3. Re: print all days of calendar ([email protected])
4. Re: Enum for natural numbers (Chadda? Fouch?)
5. Re: print all days of calendar (Daniel Fischer)
6. Re: Enum for natural numbers ([email protected])
7. Re: Enum for natural numbers (Daniel Fischer)
8. Re: print all days of calendar ([email protected])
9. Re: inserting tupels inside list as tupels in list
([email protected])
10. Re: print all days of calendar (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Mon, 21 Dec 2009 11:26:04 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 11:05:03 schrieb [email protected]:
>
> still have the problem that it says:
> "Not in scope: data constructor `Month'" but Month is declared as:
> data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Ago | Sep | Oct |
> Nov | Dec deriving (Eq,Enum,Show)
Sorry, didn't look closely enough.
Month is the name of the datatype. You want month to run through all elements
of Month, so
you need a list, namely [Jan .. Dec] (it might be necessary to include Ord in
the derived
instances for Month).
------------------------------
Message: 2
Date: Mon, 21 Dec 2009 11:28:14 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 10:56:06 schrieb [email protected]:
> Now everything works but to print Z also for negative Integers. Don't know
> how to implement the <=0 or le0 in this case again:
>
> instance Enum Nat where
> toEnum 0 = Z
> toEnum (n+1) = S(toEnum n)
Note that many frown upon (n+k)-patterns and they may be removed from the
language in
future. Use guards:
toEnum n
| condition1 = rhs1
| condition2 = rhs2
> fromEnum Z = 0
> fromEnum (S n) = 1 + fromEnum n
------------------------------
Message: 3
Date: Mon, 21 Dec 2009 11:38:14 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 11:26:04 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] print all days of calendar
> Am Montag 21 Dezember 2009 11:05:03 schrieb [email protected]:
> >
> > still have the problem that it says:
> > "Not in scope: data constructor `Month'" but Month is declared as:
> > data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Ago | Sep | Oct |
> > Nov | Dec deriving (Eq,Enum,Show)
>
> Sorry, didn't look closely enough.
> Month is the name of the datatype. You want month to run through all
> elements of Month, so
> you need a list, namely [Jan .. Dec] (it might be necessary to include Ord
> in the derived
> instances for Month).
ahhh, it works in the right order. I tried [Jan..Dec] (without the spaces)
which failed.
Which function can I use to trim the calendar of a month from the calendar of
the whole year, because I have to implement a function:
getMonth :: Month -> Calendar -> Calendar
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 4
Date: Mon, 21 Dec 2009 11:48:02 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Mon, Dec 21, 2009 at 11:28 AM, Daniel Fischer
<[email protected]> wrote:
> Am Montag 21 Dezember 2009 10:56:06 schrieb [email protected]:
>> Now everything works but to print Z also for negative Integers. Don't know
>> how to implement the <=0 or le0 in this case again:
>>
>> instance Enum Nat where
>> Â Â Â Â toEnum 0 = Z
>> Â Â Â Â toEnum (n+1) = S(toEnum n)
>
> Note that many frown upon (n+k)-patterns and they may be removed from the
> language in
> future.
In fact they _have_been_ removed from the standard in Haskell 2010, so
in ghc 6.14 they'll become an extension instead of working by default.
You just have to use n as a pattern and (n-1) instead of n in the body.
--
Jedaï
------------------------------
Message: 5
Date: Mon, 21 Dec 2009 11:53:02 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 11:38:14 schrieb [email protected]:
> Which function can I use to trim the calendar of a month from the calendar
> of the whole year, because I have to implement a function: getMonth ::
> Month -> Calendar -> Calendar
look at filter or span and break, takeWhile/dropWhile
------------------------------
Message: 6
Date: Mon, 21 Dec 2009 15:02:16 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 11:25:46 +0100
> Von: Deniz Dogan <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] Enum for natural numbers
> 2009/12/21 <[email protected]>:
> > Now everything works but to print Z also for negative Integers. Don't
> know how to implement the <=0 or le0 in this case again:
> >
> > instance Enum Nat where
> > toEnum 0 = Z
> > toEnum (n+1) = S(toEnum n)
> > fromEnum Z = 0
> > fromEnum (S n) = 1 + fromEnum n
> >
>
> Again, look into guards. You are definitely on the right track.
>
> Again, you should look into guards.
>
> instance Enum Nat where
> toEnum n | n <= 0 = Z
> | otherwise = ... -- do what with n?
> fromEnum Z = 0
> fromEnum (S n) = 1 + fromEnum n
I did it that way:
instance Enum Nat where
toEnum n | n <= 0 = Z
| otherwise = S(toEnum (n-1))
fromEnum Z = 0
fromEnum (S n) = 1 + fromEnum n
In another task I should create an infinite list: allNats :: [Nat]
I would have done it in a recursion but there issn't a parameter to call
allNats with
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 7
Date: Mon, 21 Dec 2009 15:06:38 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 15:02:16 schrieb [email protected]:
> In another task I should create an infinite list: allNats :: [Nat]
> I would have done it in a recursion but there issn't a parameter to call
> allNats with
Prelude> :t iterate
iterate :: (a -> a) -> a -> [a]
------------------------------
Message: 8
Date: Mon, 21 Dec 2009 17:04:56 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 11:53:02 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] print all days of calendar
> Am Montag 21 Dezember 2009 11:38:14 schrieb [email protected]:
> > Which function can I use to trim the calendar of a month from the
> calendar
> > of the whole year, because I have to implement a function: getMonth ::
> > Month -> Calendar -> Calendar
>
> look at filter or span and break, takeWhile/dropWhile
Dont't find any good examples of this functions that can help me. I think it
have to be somethink like that, but don't find a way that works:
getMonth :: Month -> Calendar -> Calendar
getMonth month year = filter ([1..31],month,year) (calendar year)
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
------------------------------
Message: 9
Date: Mon, 21 Dec 2009 17:10:19 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] inserting tupels inside list as
tupels in list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
issn't there a way to manage this event list easily?
-------- Original-Nachricht --------
> Datum: Sun, 20 Dec 2009 14:50:41 +0100
> Von: [email protected]
> An: [email protected]
> Betreff: Re: [Haskell-beginners] inserting tupels inside list as tupels in
> list
> I already have things like that:
>
> type Day = Int 17 data Month = Jan | Feb | Mar | Apr | May | Jun | Jul |
> Ago | Sep | Oct | Nov | Dec deriving (Eq,Enum,Show)
> type Year = Int
> type Date = (Day,Month,Year)
>
> type ID = Int
> type Event = (ID,String)
> type Organiser = [ (Date, [Event]) ]
>
> and now I should implement a function like this:
> addEvents :: Date -> [Event] -> Organiser -> Organiser
> that adds to an organiser a list of events for a specific date
>
> an example looks like this:
> xmas :: Event
> xmas = (2, "Christmas")
> aliceOrg :: Organiser
> aliceOrg = [ ( (21,Dec,2009), [panic,aliceBDay] ),
> ( (25,Dec,2009), [xmas] ) ]
>
>
> -------- Original-Nachricht --------
> > Datum: Fri, 18 Dec 2009 17:58:12 -0500
> > Von: Brent Yorgey <[email protected]>
> > An: [email protected]
> > Betreff: Re: [Haskell-beginners] inserting tupels inside list as tupels
> in list
>
> > On Fri, Dec 18, 2009 at 07:02:16PM +0100, [email protected] wrote:
> > > maybe the subject is a little bit confusing :p
> > >
> > > I have a organiser list like that and have to add events (like panic,
> > xmas, ...) which is also a type of tupel for a specific date:
> > >
> > > aliceOrg = [ ( (21,Dec,2009), [panic,aliceBDay] )
> > > ( (25,Dec,2009), [xmas] )
> > > ( (10,Jan,2010), [bobBDay] )
> > >
> > > What function(s) can I use to add these nested lists and tupels here?
> >
> > You can use all the functions for manipulating lists and tuples in the
> > standard libraries... I'm not entirely sure what you are asking.
> >
> > Let me suggest, however, that you probably don't want to be using
> > tuples so much; make your own data types. Something like this:
> >
> > type Day = Int
> > data Month = Jan | Feb | ...
> > type Year = Int
> >
> > data Date = Date Day Month Year
> >
> > data CalEntry = CalEntry Date [Event]
> > data Event = ...
> >
> > type Organizer = [CalEntry]
> >
> > This is much less confusing since instead of just tuples everywhere
> > you have specific types that say exactly what the data represents.
> >
> > -Brent
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
>
> --
> Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
> http://portal.gmx.net/de/go/dsl02
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
------------------------------
Message: 10
Date: Mon, 21 Dec 2009 17:22:18 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 17:04:56 schrieb [email protected]:
> -------- Original-Nachricht --------
>
> > Datum: Mon, 21 Dec 2009 11:53:02 +0100
> > Von: Daniel Fischer <[email protected]>
> > An: [email protected]
> > CC: [email protected]
> > Betreff: Re: [Haskell-beginners] print all days of calendar
> >
> > Am Montag 21 Dezember 2009 11:38:14 schrieb [email protected]:
> > > Which function can I use to trim the calendar of a month from the
> >
> > calendar
> >
> > > of the whole year, because I have to implement a function: getMonth ::
> > > Month -> Calendar -> Calendar
> >
> > look at filter or span and break, takeWhile/dropWhile
>
> Dont't find any good examples of this functions that can help me. I think
> it have to be somethink like that, but don't find a way that works:
> getMonth :: Month -> Calendar -> Calendar
> getMonth month year = filter ([1..31],month,year) (calendar year)
Prelude> :t filter
filter :: (a -> Bool) -> [a] -> [a]
So we need a predicate on the type of list elements.
getMonth month cal = filter predicate cal
where
predicate (d,m,y) = ??
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 18, Issue 20
*****************************************