inserting tupels inside list as tupels in list

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? -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser

On Fri, Dec 18, 2009 at 07:02:16PM +0100, kane96@gmx.de 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

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
An: beginners@haskell.org Betreff: Re: [Haskell-beginners] inserting tupels inside list as tupels in list
On Fri, Dec 18, 2009 at 07:02:16PM +0100, kane96@gmx.de 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 Beginners@haskell.org 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

issn't there a way to manage this event list easily? -------- Original-Nachricht --------
Datum: Sun, 20 Dec 2009 14:50:41 +0100 Von: kane96@gmx.de An: beginners@haskell.org 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
An: beginners@haskell.org Betreff: Re: [Haskell-beginners] inserting tupels inside list as tupels in list On Fri, Dec 18, 2009 at 07:02:16PM +0100, kane96@gmx.de 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 Beginners@haskell.org 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 Beginners@haskell.org 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

On Mon, Dec 21, 2009 at 5:10 PM,
issn't there a way to manage this event list easily?
Sure there is, on the other hand you already had a lot of help on this mainling list, maybe you could try to finish this by yourself ? Some pointers though : - first I would like to point that while Day/Month/Year is the convention in some countries, (Year,Month,Day) makes a lot more sense from an informatic point of view given that the lexicographic order on that corresponds to the date order (add Ord to the derivation for your Month type) - second, a list may not be the most appropriate for associating date and event, a Map (from Data.Map) may be better. -- Jedaï
participants (3)
-
Brent Yorgey
-
Chaddaï Fouché
-
kane96@gmx.de