I didn't try to compile this:
import Control.Arrow (first)
import System.Random (Random(..))
instance Random Dir where
randomR (lo, hi) gen = first fromEnum (randomR (toEnum lo)
(toEnum hi) gen)
random gen = randomR (minBound, maxBound)
But something along those lines should help you
Am Samstag 02 Mai 2009 21:22:26 schrieb Ketil Malde:
> Rahul Kapoor writes:
> >> *Main> toEnum 2
> >
> > ghci does not know what type of enum you want to create from the number
> > 2. Try: toEnum 2 :: DayOfWeek
> >
> > That said, I would expect "toEnum 2" to give an error like: 'Ambiguous
> > type
Rahul Kapoor writes:
>> *Main> toEnum 2
>
> ghci does not know what type of enum you want to create from the number 2.
> Try: toEnum 2 :: DayOfWeek
>
> That said, I would expect "toEnum 2" to give an error like: 'Ambiguous
> type variable `a''. So I am not sure why your error message says:
>
Am Samstag 02 Mai 2009 20:00:54 schrieb Rahul Kapoor:
> > OK, I think what you're saying is to work with (random) integers and use
> > fromEnum and toEnum to get corresponding DayOfWeek. But I get this when I
> > try to use toEnum:
> >
> > *Main> toEnum 2
>
> ghci does not know what type of enum yo
I intuited that that's what the problem was.
Thanks,
Michael
--- On Sat, 5/2/09, Rahul Kapoor wrote:
From: Rahul Kapoor
Subject: Re: [Haskell-cafe] Generating random enums
To: "michael rice"
Cc: "John Van Enk" , haskell-cafe@haskell.org
Date: Saturday, May 2, 200
> OK, I think what you're saying is to work with (random) integers and use
> fromEnum and toEnum to get corresponding DayOfWeek. But I get this when I
> try to use toEnum:
>
> *Main> toEnum 2
ghci does not know what type of enum you want to create from the number 2.
Try: toEnum 2 :: DayOfWeek
Tha
old-time-1.0.0.1 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
2
*Main> toEnum 2
*** Exception: Prelude.Enum.().toEnum: bad argument
*Main>
Michael
--- On Fri, 5/1/09, John Van Enk wrote:
From: John Van Enk
Subject: Re: [Haskell-cafe] Generating random enums
To:
On Fri, May 1, 2009 at 11:08 AM, Thomas Hartman wrote:
> For quickchecking, the code below "cheats" by not defining the
> coarbitrary funciton, which I confess I don't really understand and
> never use.
coarbitrary is simple; it's used for generating arbitrary functions.
If you don't know how to
On Fri, May 01, 2009 at 01:08:26PM -0500, Thomas Hartman wrote:
> For quickchecking, the code below "cheats" by not defining the
> coarbitrary funciton, which I confess I don't really understand and
> never use.
FWIW, QuickCheck 2 separates 'coarbitrary' in a different class.
--
Felipe.
_
So... I must say I am rather pleased with the following code.
It allows you to use any value of type Bounded and Enum as a member of
Random, or Arbitrary, which means you can quickCheck properties on it
as well.
For quickchecking, the code below "cheats" by not defining the
coarbitrary funciton,
see
http://www.mail-archive.com/haskell-cafe@haskell.org/msg38528.html
for some ideas, particularly antoine latter's answer.
2009/5/1 michael rice :
> I'm using the code below to generate random days of the week
> [Monday..Sunday].
>
> Is there a better/shorter way to do this?
>
> Michael
>
> ==
When you derive Enum, you get fromEnum and toEnum for free. You don't need
your dow2Int stuff or int2Dow. Replace those with fromEnum and toEnum
respectively.
/jve
On Fri, May 1, 2009 at 12:26 PM, michael rice wrote:
> I'm using the code below to generate random days of the week
> [Monday..Su
12 matches
Mail list logo