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: Large tables and GHC. (Stephen Tetley)
2. Re: Re: Applicability of FP unchanging things to real world
changing things (Shawn Willden)
3. find element of tupels (kane96)
4. Re: find element of tupels (Magnus Therning)
5. Re: Large tables and GHC. (Patrick LeBoutillier)
6. Re: find element of tupels (Andrew Sackville-West)
7. Re: find element of tupels ([email protected])
8. Enum for natural numbers ([email protected])
9. Re: Enum for natural numbers (Brandon S. Allbery KF8NH)
10. Re: find element of tupels (Henk-Jan van Tuyl)
----------------------------------------------------------------------
Message: 1
Date: Thu, 17 Dec 2009 09:05:51 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Large tables and GHC.
To: "Sherard D." <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi Sherard
You could use Data.Array.IO to read the data at runtime. Its not ideal
as as well as moving the array read to runtime (the data file must be
present somewhere) it puts you in the IO monad...
I'm supposing you really want the equivalent of the C idiom where
bitmaps or whatever are stored as char or byte arrays:
const char bitmap1[] = { 0xFF, ... }
GHC has array literals between #'s, here is a snippet from code
generate by Alex, the lexer generator:
data AlexAddr = AlexA# Addr#
alex_deflt :: AlexAddr
alex_deflt = AlexA# "\xff\xff\xff\xff\xff\xff\xff\xff"#
Unfortunately I can't seem to find mention of array literals in the
GHC user guide only the related 'Magic Hash' and I've never used array
literals directly myself - only with code generated by Alex, so I
can't really say how they work. Hopefully someone will add a better
explanation soon.
Best wishes
Stephen
2009/12/17 Sherard D. <[email protected]>:
> Hi,
> I have a couple of rather large byte tables that I'd like to use. I decided
> to use them as arrays because I figured such large tables wouldn't work well
> as lists.
------------------------------
Message: 2
Date: Thu, 17 Dec 2009 08:01:31 -0700
From: Shawn Willden <[email protected]>
Subject: Re: [Haskell-beginners] Re: Applicability of FP unchanging
things to real world changing things
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Monday 14 December 2009 09:54:53 am Gregg Reynolds wrote:
> Youschkevitch's fascinating history of the concept
> <http://www.springerlink.com/content/p3x21230u404p13h/> might be
> useful.
Too bad it's paywalled :-(
Shawn.
------------------------------
Message: 3
Date: Thu, 17 Dec 2009 16:03:59 +0100
From: "kane96" <[email protected]>
Subject: [Haskell-beginners] find element of tupels
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi,
I have a list of tuples: [(Jan, 31),(Feb, 28),(Mar, 31),...] called
monthAndMaxDay
Date is:
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)
Now I want to check if a date is legal:
legalDate :: Date -> Bool
legalDate (myDay, myMonth, myYear) =
not (myDay <= 0) && myDay >= (find ((== myMonth) . fst) monthAndMaxDay) .
snd
the find works to search for the month in the first element of every tupel but
at the end I have to check the second value of the tupel (the day) that it
issn't higher than the maximal number of days in that month. Where do I have to
set the "snd" correctly. Here I get the error: Couldn't match expected type `b
-> c'
against inferred type `Maybe (Month, Day)'
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
------------------------------
Message: 4
Date: Thu, 17 Dec 2009 15:21:13 +0000
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] find element of tupels
To: kane96 <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 17, 2009 at 3:03 PM, kane96 <[email protected]> wrote:
> Hi,
> I have a list of tuples: [(Jan, 31),(Feb, 28),(Mar, 31),...] called
> monthAndMaxDay
>
> Date is:
> 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)
>
> Now I want to check if a date is legal:
> legalDate :: Date -> Bool
> legalDate (myDay, myMonth, myYear) =
> Â Â not (myDay <= 0) && myDay >= Â (find ((== myMonth) . fst)
> monthAndMaxDay) . snd
>
> the find works to search for the month in the first element of every tupel
> but at the end I have to check the second value of the tupel (the day) that
> it issn't higher than the maximal number of days in that month. Where do I
> have to set the "snd" correctly. Here I get the error: Couldn't match
> expected type `b -> c'
> Â Â Â Â Â against inferred type `Maybe (Month, Day)'
First of all I'd take a look at the function Prelude.lookup, it'll be
useful in this case.
Using that function I'd do something like this:
legalDate (myDay, myMonth, myYear) = maybe False id $ do
days <- lookup myMonth monthAndMaxDay
return (myDay <= days)
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
------------------------------
Message: 5
Date: Thu, 17 Dec 2009 10:41:51 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] Large tables and GHC.
To: "Sherard D." <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
On Wed, Dec 16, 2009 at 11:05 PM, Sherard D. <[email protected]> wrote:
> Hi,
>
> I have a couple of rather large byte tables that I'd like to use. I decided
> to use them as arrays because I figured such large tables wouldn't work well
> as lists.
>
> table1 = listArray (0, 25599) [...]
> table2 = listArray (0, 25599) [...]
>
> This is how my code looks, minus the large tables. However, the problem is
> that the large tables are loaded as a list first, and then converted to an
> array. This is indeed a very big problem, as trying to compile with GHC
> takes an unacceptably long time.
If compilating time is only an issue while developping, maybe you can
put your tables in a separate module? That way they only get compiled
once (or when you change them) and they don't get recompiled when you
change the rest of your program.
Patrick
>
> Is there any way I can get around this?
>
>
> - Sherard
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 6
Date: Thu, 17 Dec 2009 08:09:10 -0800
From: Andrew Sackville-West <[email protected]>
Subject: Re: [Haskell-beginners] find element of tupels
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Thu, Dec 17, 2009 at 04:03:59PM +0100, kane96 wrote:
> Hi,
> I have a list of tuples: [(Jan, 31),(Feb, 28),(Mar, 31),...] called
> monthAndMaxDay
>
> Date is:
> 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)
>
> Now I want to check if a date is legal:
> legalDate :: Date -> Bool
> legalDate (myDay, myMonth, myYear) =
> not (myDay <= 0) && myDay >= (find ((== myMonth) . fst) monthAndMaxDay)
> . snd
>
> the find works to search for the month in the first element of every tupel
> but at the end I have to check the second value of the tupel (the day) that
> it issn't higher than the maximal number of days in that month. Where do I
> have to set the "snd" correctly. Here I get the error: Couldn't match
> expected type `b -> c'
> against inferred type `Maybe (Month, Day)'
I'm sure the error message goes on to say something like:
in the first argument of (.)
namely (find ((== myMonth) . fst) monthAndMaxDay)
...
you have to interpret this error message a little bit. It is saying
the composition operator (.) is expecting a function of type b -> c in
it's first argument (or on the left-hand side), but you have provided
something of type Maybe (Month, Day). This type is what that (find...)
evaluates to.
I'm missing the correct terminology here, but you cannot provide
something that is fully evaluable on the left-hand side of (.). It
needs to be something that evaluates to a function of one
argument. That argument will be supplied by the function provided on
the right hand side of (.).
So, at a minimum, you need to swap your snd and your (find...), but
that doesn't solve the problem of getting the tuple out of the Maybe
monad that find returns.
A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url :
http://www.haskell.org/pipermail/beginners/attachments/20091217/f14541dd/attachment-0001.bin
------------------------------
Message: 7
Date: Thu, 17 Dec 2009 17:18:41 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] find element of tupels
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
thanks Magnus, great, works so far. I added to check that myDay have to be
greater 0:
legalDate :: Date -> Bool
legalDate (myDay, myMonth, myYear) = maybe False id $ do
days <- lookup myMonth monthAndMaxDay
return (not (myDay <= 0) && (myDay <= days))
Another thing is, that I have to check for leapYears. I have a function that
checks if a year is a leap year
isLeapYear :: Int -> Bool
isLeapYear year = mod year 4 == 0
monthAndMaxDay has 30 days for February which have to be fix. So i have to
check in legalDate if the year is a leap year. If so I have to check myDay in
February for 29 days, otherwise for 28 days. How can I implement this to
isLegalDate?
-------- Original-Nachricht --------
> Datum: Thu, 17 Dec 2009 15:21:13 +0000
> Von: Magnus Therning <[email protected]>
> An: kane96 <[email protected]>
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] find element of tupels
> On Thu, Dec 17, 2009 at 3:03 PM, kane96 <[email protected]> wrote:
> > Hi,
> > I have a list of tuples: [(Jan, 31),(Feb, 28),(Mar, 31),...] called
> monthAndMaxDay
> >
> > Date is:
> > 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)
> >
> > Now I want to check if a date is legal:
> > legalDate :: Date -> Bool
> > legalDate (myDay, myMonth, myYear) =
> > Â Â not (myDay <= 0) && myDay >= Â (find ((== myMonth) . fst)
> monthAndMaxDay) . snd
> >
> > the find works to search for the month in the first element of every
> tupel but at the end I have to check the second value of the tupel (the day)
> that it issn't higher than the maximal number of days in that month. Where
> do I have to set the "snd" correctly. Here I get the error: Couldn't match
> expected type `b -> c'
> > Â Â Â Â Â against inferred type `Maybe (Month, Day)'
>
>
> First of all I'd take a look at the function Prelude.lookup, it'll be
> useful in this case.
>
> Using that function I'd do something like this:
>
> legalDate (myDay, myMonth, myYear) = maybe False id $ do
> days <- lookup myMonth monthAndMaxDay
> return (myDay <= days)
>
> /M
>
> --
> Magnus Therning (OpenPGP: 0xAB4DFBA4)
> magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
> http://therning.org/magnus identi.ca|twitter: magthe
--
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02
------------------------------
Message: 8
Date: Thu, 17 Dec 2009 18:21:21 +0100
From: [email protected]
Subject: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I have data Nat = Z | S Nat deriving (Eq,Ord,Show)
toEnum should return Z for negative numbers. I did something like this but the
problem is I don't know how to set "less than". I tried > and lt:
instance Enum Nat where
toEnum (gt 0) = S Z
toEnum (lt 1) = Z
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
------------------------------
Message: 9
Date: Thu, 17 Dec 2009 13:56:30 -0500
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Enum for natural numbers
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Dec 17, 2009, at 12:21 , [email protected] wrote:
> toEnum should return Z for negative numbers. I did something like
> this but the problem is I don't know how to set "less than". I tried
> > and lt:
>
> instance Enum Nat where
> toEnum (gt 0) = S Z
> toEnum (lt 1) = Z
Take a look at guards.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20091217/edb90242/PGP-0001.bin
------------------------------
Message: 10
Date: Thu, 17 Dec 2009 20:44:34 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] find element of tupels
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Thu, 17 Dec 2009 17:18:41 +0100, <[email protected]> wrote:
> thanks Magnus, great, works so far. I added to check that myDay have to
> be greater 0:
>
> legalDate :: Date -> Bool
> legalDate (myDay, myMonth, myYear) = maybe False id $ do
> days <- lookup myMonth monthAndMaxDay
> return (not (myDay <= 0) && (myDay <= days))
>
> Another thing is, that I have to check for leapYears. I have a function
> that checks if a year is a leap year
>
> isLeapYear :: Int -> Bool
> isLeapYear year = mod year 4 == 0
That is not entirely correct; from package time:
isLeapYear :: Integer -> Bool
isLeapYear year = (mod year 4 == 0) && ((mod year 400 == 0) || not (mod
year 100 == 0))
>
> monthAndMaxDay has 30 days for February which have to be fix. So i have
> to check in legalDate if the year is a leap year. If so I have to check
> myDay in February for 29 days, otherwise for 28 days. How can I
> implement this to isLegalDate?
Use fromGregorianValid from package time.
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
--
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 18, Issue 13
*****************************************