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 ([email protected])
2. Re: Enum for natural numbers ([email protected])
3. Re: Enum for natural numbers (jean verdier)
4. Re: print all days of calendar (Daniel Fischer)
5. Re: print all days of calendar ([email protected])
6. Re: Enum for natural numbers ([email protected])
7. Re: print all days of calendar (Daniel Fischer)
8. Re: print all days of calendar ([email protected])
9. Re: print all days of calendar (Daniel Fischer)
10. Re: Enum for natural numbers (Daniel Fischer)
11. Re: Enum for natural numbers ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Mon, 21 Dec 2009 17:39:49 +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 17:22:18 +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 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) = ??
it has to match the given month and year. But don't know how to define it.
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 2
Date: Mon, 21 Dec 2009 18:27:03 +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 15:06:38 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] Enum for natural numbers
> 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]
this works:
allNats = (iterate (1+) 1)
but it doesn't match my declaration:
allNats :: [Nat]
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 3
Date: Mon, 21 Dec 2009 19:40:23 +0100
From: jean verdier <[email protected]>
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain
your type is
data Nat = S Nat | Z
and not
data Nat = 1 + Nat | 0
On Mon, 2009-12-21 at 18:27 +0100, [email protected] wrote:
> -------- Original-Nachricht --------
> > Datum: Mon, 21 Dec 2009 15:06:38 +0100
> > Von: Daniel Fischer <[email protected]>
> > An: [email protected]
> > CC: [email protected]
> > Betreff: Re: [Haskell-beginners] Enum for natural numbers
>
> > 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]
>
> this works:
> allNats = (iterate (1+) 1)
> but it doesn't match my declaration:
> allNats :: [Nat]
>
>
------------------------------
Message: 4
Date: Mon, 21 Dec 2009 19:54:09 +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:39:49 schrieb [email protected]:
> > 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) = ??
>
> it has to match the given month and year. But don't know how to define it.
Does (==) ring a few bells?
------------------------------
Message: 5
Date: Mon, 21 Dec 2009 20:47:38 +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 19:54:09 +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 17:39:49 schrieb [email protected]:
> > > 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) = ??
> >
> > it has to match the given month and year. But don't know how to define
> it.
>
> Does (==) ring a few bells?
not really...
--
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02
------------------------------
Message: 6
Date: Mon, 21 Dec 2009 21:02:06 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: jean verdier <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 19:40:23 +0100
> Von: jean verdier <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] Enum for natural numbers
> your type is
> data Nat = S Nat | Z
> and not
> data Nat = 1 + Nat | 0
Do I have to use something like fromEnum (S Z)? Or or the iteration wrong?
>
> On Mon, 2009-12-21 at 18:27 +0100, [email protected] wrote:
> > -------- Original-Nachricht --------
> > > Datum: Mon, 21 Dec 2009 15:06:38 +0100
> > > Von: Daniel Fischer <[email protected]>
> > > An: [email protected]
> > > CC: [email protected]
> > > Betreff: Re: [Haskell-beginners] Enum for natural numbers
> >
> > > 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]
> >
> > this works:
> > allNats = (iterate (1+) 1)
> > but it doesn't match my declaration:
> > allNats :: [Nat]
> >
> >
--
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02
------------------------------
Message: 7
Date: Mon, 21 Dec 2009 21:12:48 +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 20:47:38 schrieb [email protected]:
> >
> > Does (==) ring a few bells?
>
> not really...
Prelude> let okay k = k^3 `mod` 13 == 5 in filter okay [1 .. 30]
[7,8,11,20,21,24]
Now, you don't want the numbers between 1 and 30 inclusive whose cube modulo 13
is 5, but
the dates in a given month.
getMonth :: Month -> Calendar -> Calendar
getMonth month [(1,Jan,y),(2,Jan,y) ... (31,Dec,y)]
------------------------------
Message: 8
Date: Mon, 21 Dec 2009 21:39:38 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] print all days of calendar
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 21:12:48 +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 20:47:38 schrieb [email protected]:
> > >
> > > Does (==) ring a few bells?
> >
> > not really...
>
> Prelude> let okay k = k^3 `mod` 13 == 5 in filter okay [1 .. 30]
> [7,8,11,20,21,24]
>
> Now, you don't want the numbers between 1 and 30 inclusive whose cube
> modulo 13 is 5, but
> the dates in a given month.
>
> getMonth :: Month -> Calendar -> Calendar
> getMonth month [(1,Jan,y),(2,Jan,y) ... (31,Dec,y)]
more like this:
getMonth month calendar = calendar filter ([1..31], month, year)
but it doesn't make sense
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 9
Date: Mon, 21 Dec 2009 22:00:58 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] print all days of calendar
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag 21 Dezember 2009 21:39:38 schrieb [email protected]:
> -------- Original-Nachricht --------
>
> > Datum: Mon, 21 Dec 2009 21:12:48 +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 20:47:38 schrieb [email protected]:
> > > > Does (==) ring a few bells?
> > >
> > > not really...
> >
> > Prelude> let okay k = k^3 `mod` 13 == 5 in filter okay [1 .. 30]
> > [7,8,11,20,21,24]
> >
> > Now, you don't want the numbers between 1 and 30 inclusive whose cube
> > modulo 13 is 5, but
> > the dates in a given month.
> >
> > getMonth :: Month -> Calendar -> Calendar
> > getMonth month [(1,Jan,y),(2,Jan,y) ... (31,Dec,y)]
>
> more like this:
> getMonth month calendar = calendar filter ([1..31], month, year)
> but it doesn't make sense
No.
type Calendar = [Date]
type Day = Int
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)
So the calendar in "getMonth month calendar" is a list of date-triples as
illustrated
above.
Prelude> :t filter
filter :: (a -> Bool) -> [a] -> [a]
So filter takes
1) a predicate (a function of type (a -> Bool))
2) a list
as arguments.
getMonth :: Month -> [Date] -> [Date]
One of the arguments to getMonth is a list, and the result should be a list of
the same
type, thus it's natural to pass that list unchanged to filter.
getMonth month calendar = filter predicateThatYouNeed calendar
What remains is to define predicateThatYouNeed. It will somehow involve the
other argument
to getMonth, namely month. And it must map (Day,Month,Year) triples to Bool.
------------------------------
Message: 10
Date: Mon, 21 Dec 2009 22:06:46 +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 21:02:06 schrieb [email protected]:
> > your type is
> > data Nat = S Nat | Z
> > and not
> > data Nat = 1 + Nat | 0
>
> Do I have to use something like fromEnum (S Z)? Or or the iteration wrong?
Which operation on Nat corresponds to (1 +) on Int[eger] ?
------------------------------
Message: 11
Date: Mon, 21 Dec 2009 22:40:54 +0100
From: [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="iso-8859-1"
-------- Original-Nachricht --------
> Datum: Mon, 21 Dec 2009 22:06:46 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected], jean verdier <[email protected]>
> Betreff: Re: [Haskell-beginners] Enum for natural numbers
> Am Montag 21 Dezember 2009 21:02:06 schrieb [email protected]:
> > > your type is
> > > data Nat = S Nat | Z
> > > and not
> > > data Nat = 1 + Nat | 0
> >
> > Do I have to use something like fromEnum (S Z)? Or or the iteration
> wrong?
>
> Which operation on Nat corresponds to (1 +) on Int[eger] ?
I implemented it:
allNats :: [Nat]
allNats = iterate S Z
--
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
End of Beginners Digest, Vol 18, Issue 21
*****************************************