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: Time interval calculation (Daniel Fischer)
2. Re: Time interval calculation (Maciej Piechotka)
3. Randomly selecting a data constructor (Evgenij Merenkov)
4. Re: Randomly selecting a data constructor (Thomas Davie)
5. Re: homogeneous value list (Yitzchak Gale)
6. RE: Randomly selecting a data constructor (Evgenij Merenkov)
7. Re: Randomly selecting a data constructor (Yitzchak Gale)
----------------------------------------------------------------------
Message: 1
Date: Sat, 13 Mar 2010 23:08:31 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Time interval calculation
To: legajid <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Samstag 13 März 2010 23:09:48 schrieb legajid:
> I tried
>
> !t1f <- gettime
>
> and i got an error message :
> premier.hs:92:1: Illegal bang-pattern (use -XBangPatterns)
> Failed, modules loaded: none.
>
>
> t1f <- !gettime gives :
> premier.hs:92:8: parse error on input `!'
> Failed, modules loaded: none.
Ah yes, you must tell GHC that you want to use bang-patterns, best with a
{-# LANGUAGE BangPatterns #-}
pragma right at the top of the file
(you can too easily forget to pass -XBangPatterns on the command ine).
------------------------------
Message: 2
Date: Sun, 14 Mar 2010 03:21:21 +0000
From: Maciej Piechotka <[email protected]>
Subject: [Haskell-beginners] Re: Time interval calculation
To: [email protected]
Message-ID: <1268536880.17088.6.ca...@picard>
Content-Type: text/plain; charset="utf-8"
On Sat, 2010-03-13 at 21:20 +0100, legajid wrote:
> Hi,
> my following code should show time before executing listeprem, then time
> after execution.
>
> import System.Time
import Control.Exception
> gettime :: IO ClockTime
> gettime = getClockTime
>
> main=do
> t1d <- gettime
> let t1=last (listeprem 5000)
evaluate t1
> t1f <- gettime
> putStrLn ("Methode 1 : " ++ show t1d)
> putStrLn (" " ++ show t1)
> putStrLn (" " ++ show t1f)
>
> Looking at the screen, t1d is displayed then, after a few seconds, t1
> and t1f.
> But, t1d and t1f are equal.
> It seems like if t1d and t1f where calculated at start of procedure,
> before we need calculating t1 for putStrLn.
> How can i have t1f evaluated after t1, so i can calculate time elapsed
> for calculation of t1?
>
> Thanks,
> Didier
>
>
Haskell calculates the expression when it needs. So
let t1 = last (listeprem 5000)
Means rather 't1 is expression ....' then calculate .... and save result
in t1. evaluate is a nice function that forces the evaluation.
Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100313/9fb84440/attachment-0001.bin
------------------------------
Message: 3
Date: Sun, 14 Mar 2010 10:57:22 +0000
From: Evgenij Merenkov <[email protected]>
Subject: [Haskell-beginners] Randomly selecting a data constructor
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"
Hello.
I have the following data and it's constructors:
FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 | NoFigure
I need to randomly return one of them in a function. The obvious solution to
me, is simply using a random number generator and case statement, where each
value generated is associated with each data constructor. Like this:
import System.Random
randomFigType :: IO FigType
randomFigure = do
x <- randomRIO (1::Int,11::Int)
return $ case x of
1 -> TR1
2 -> TR2
3 -> TR3
e t.c.
But is there a more direct way to do this?
_________________________________________________________________
Hotmail: Trusted email with Microsofts powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100314/a3166577/attachment-0001.html
------------------------------
Message: 4
Date: Sun, 14 Mar 2010 11:08:59 +0000
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
To: Evgenij Merenkov <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"
data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
NoFigure
deriving (Enum)
randomFigure :: IO FigType
randomFigure = toEnum <$> randomRIO (1,11)
Bob
On 14 Mar 2010, at 10:57, Evgenij Merenkov wrote:
> Hello.
>
> I have the following data and it's constructors:
>
> FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 | NoFigure
>
> I need to randomly return one of them in a function. The obvious solution to
> me, is simply using a random number generator and case statement, where each
> value generated is associated with each data constructor. Like this:
>
> import System.Random
>
> randomFigType :: IO FigType
> randomFigure = do
> x <- randomRIO (1::Int,11::Int)
> return $ case x of
> 1 -> TR1
> 2 -> TR2
> 3 -> TR3
> e t.c.
>
> But is there a more direct way to do this?
>
> Hotmail: Trusted email with Microsofts powerful SPAM protection. Sign up
> now. _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100314/16b65e08/attachment-0001.html
------------------------------
Message: 5
Date: Sun, 14 Mar 2010 13:18:21 +0200
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] homogeneous value list
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Brent Yorgey wrote:
>>> I would argue that it's good practice simply to never call head at
>>> all. I stopped a while ago, and I haven't missed it. =)
Daniel Fischer wrote:
>> I would argue that in
>> snub = map head . group . sort
>> and the like, calling head is perfectly cromulent. But apart from that, I
>> don't remember using head in the last years.
> Ah, true, I guess that's the one place I've used head as well. =)
snub = concatMap (take 1) . group . sort
Perhaps a tiny bit slower if it doesn't get optimized. But I consider
using head a premature optimization.
listToMaybe is another helpful tool for getting rid of head.
Enjoy,
Yitz
------------------------------
Message: 6
Date: Sun, 14 Mar 2010 11:21:41 +0000
From: Evgenij Merenkov <[email protected]>
Subject: RE: [Haskell-beginners] Randomly selecting a data constructor
To: <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Thank you.
Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
From: [email protected]
Date: Sun, 14 Mar 2010 11:08:59 +0000
CC: [email protected]
To: [email protected]
data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
NoFigure deriving (Enum)
randomFigure :: IO FigTyperandomFigure = toEnum <$> randomRIO (1,11)
Bob
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
https://signup.live.com/signup.aspx?id=60969
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100314/8ac133de/attachment-0001.html
------------------------------
Message: 7
Date: Sun, 14 Mar 2010 13:39:19 +0200
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
To: Thomas Davie <[email protected]>
Cc: [email protected], Evgenij Merenkov <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Thomas Davie wrote:
> data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
> NoFigure
> deriving (Enum)
> randomFigure :: IO FigType
> randomFigure = toEnum <$> randomRIO (1,11)
You actually want randomRIO (0,10).
If you don't want to have to remember that, or to remember
to change "10" whenever the number of constructors changes,
you can use:
> data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
> NoFigure
> deriving (Enum, Bounded)
> randomFigure :: IO FigType
> randomFigure = toEnum <$>
> randomRIO (fromEnum (minBound :: FigType), fromEnum maxBound)
Regards,
Yitz
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 21, Issue 15
*****************************************