[Haskell-beginners] inserting tupels inside list as tupels in list

kane96 at gmx.de kane96 at gmx.de
Mon Dec 21 11:10:19 EST 2009


issn't there a way to manage this event list easily?

-------- Original-Nachricht --------
> Datum: Sun, 20 Dec 2009 14:50:41 +0100
> Von: kane96 at gmx.de
> An: beginners at 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 <byorgey at seas.upenn.edu>
> > An: beginners at 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 at 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 at 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 at 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


More information about the Beginners mailing list