What is the minimum I need to do to get this function to generate a three
direction tuple?
Michael
=
import System.Random
import Data.Ord
data Dir
= North
| South
| East
| West
deriving (Show, Read, Eq, Enum, Ord, Bounded)
threeDirs :: StdGen -
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
-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 vane...@gmail.com wrote:
From: John Van Enk vane...@gmail.com
Subject: Re: [Haskell-cafe] Generating
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
That
I intuited that that's what the problem was.
Thanks,
Michael
--- On Sat, 5/2/09, Rahul Kapoor r...@trie.org wrote:
From: Rahul Kapoor r...@trie.org
Subject: Re: [Haskell-cafe] Generating random enums
To: michael rice nowg...@yahoo.com
Cc: John Van Enk vane...@gmail.com, haskell-cafe
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 you want to
Rahul Kapoor r...@trie.org 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 21:22:26 schrieb Ketil Malde:
Rahul Kapoor r...@trie.org 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
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
==
[mich...@localhost ~]$ ghci dow
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading
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 nowg...@yahoo.com wrote:
I'm using the code below to generate random days of the
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 nowg...@yahoo.com:
I'm using the code below to generate random days of the week
[Monday..Sunday].
Is there a better/shorter way to do this?
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,
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.
On Fri, May 1, 2009 at 11:08 AM, Thomas Hartman tphya...@gmail.com 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
14 matches
Mail list logo