summaryrefslogtreecommitdiff
path: root/ghc/lib/std/Random.lhs
Commit message (Collapse)AuthorAgeFilesLines
* [project @ 2002-02-12 15:17:13 by simonmar]simonmar2002-02-121-307/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Switch over to the new hierarchical libraries --------------------------------------------- This commit reorganises our libraries to use the new hierarchical module namespace extension. The basic story is this: - fptools/libraries contains the new hierarchical libraries. Everything in here is "clean", i.e. most deprecated stuff has been removed. - fptools/libraries/base is the new base package (replacing "std") and contains roughly what was previously in std, lang, and concurrent, minus deprecated stuff. Things that are *not allowed* in libraries/base include: Addr, ForeignObj, ByteArray, MutableByteArray, _casm_, _ccall_, ``'', PrimIO For ByteArrays and MutableByteArrays we use UArray and STUArray/IOUArray respectively now. Modules previously called PrelFoo are now under fptools/libraries/GHC. eg. PrelBase is now GHC.Base. - fptools/libraries/haskell98 provides the Haskell 98 std. libraries (Char, IO, Numeric etc.) as a package. This package is enabled by default. - fptools/libraries/network is a rearranged version of the existing net package (the old package net is still available; see below). - Other packages will migrate to fptools/libraries in due course. NB. you need to checkout fptools/libraries as well as fptools/hslibs now. The nightly build scripts will need to be tweaked. - fptools/hslibs still contains (almost) the same stuff as before. Where libraries have moved into the new hierarchy, the hslibs version contains a "stub" that just re-exports the new version. The idea is that code will gradually migrate from fptools/hslibs into fptools/libraries as it gets cleaned up, and in a version or two we can remove the old packages altogether. - I've taken the opportunity to make some changes to the build system, ripping out the old hslibs Makefile stuff from mk/target.mk; the new package building Makefile code is in mk/package.mk (auto-included from mk/target.mk). The main improvement is that packages now register themselves at make boot time using ghc-pkg, and the monolithic package.conf in ghc/driver is gone. I've updated the standard packages but haven't tested win32, graphics, xlib, object-io, or OpenGL yet. The Makefiles in these packages may need some further tweaks, and they'll need pkg.conf.in files added. - Unfortunately all this rearrangement meant I had to bump the interface-file version and create a bunch of .hi-boot-6 files :-(
* [project @ 2001-08-29 10:49:28 by simonmar]simonmar2001-08-291-6/+8
| | | | | Add genRange method to class RandomGen, as per the revised Haskell 98 library report.
* [project @ 2001-02-28 00:01:01 by qrczak]qrczak2001-02-281-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add {intToInt,wordToWord}{8,16,32}# primops. WARNING: Not implemented in ncg for Alpha and Sparc. But -O -fasm is not going to go far anyway because of other omissions. * Have full repertoire of 8,16,32-bit signed and unsigned MachMisc.Size values. Again only x86 is fully supported. They are used for {index,read,write}{Int,Word}{8,16,32}{OffAddr,Array}# and {intToInt,wordToWord}{8,16,32}# primops. * Have full repertoire of {index,read,write}\ {Char,WideChar,Int,Word,Addr,Float,Double,StablePtr,\ {Int,Word}{8,16,32,64}}\ {OffAddr,Array} primops and appropriate instances. There were various omissions in various places. * Add {plus,minus,times}Word# primops to avoid so many Word# <-> Int# coercions. * Rewrite modules PrelWord and PrelInt almost from scratch. * Simplify fromInteger and realToFrac rules. For each of {Int,Word}{8,16,32} there is just a pair of fromInteger rules replacing the source or target type with Int or Word. For {Int,Word,Int64,Word64} there are rules from any to any. Don't include rules which are derivable from inlining anyway, e.g. those mentioning Integer. Old explicit coercions are simply defined as appropriately typed fromInteger. * Various old coercion functions marked as deprecated. * Add instance Bits Int, and instance {Show,Num,Real,Enum,Integral,Bounded,Ix,Read,Bits} Word. * Coercions to sized integer types consistently behave as cutting the right amount of bits from the infinite two-complement representation. For example (fromIntegral (-1 :: Int8) :: Word64) == maxBound. * ghc/tests/numeric/should_run/arith011 tests {Int,Word}64 and instance Bits Int, and does not try to use overflowing toEnum. arith011.stdout is not updated yet because of a problem I will tell about soon. * Move fromInteger and realToFrac from Prelude to PrelReal. Move fromInt from PrelNum to PrelReal and define as fromInteger. Define toInt as fromInteger. fromInteger is the place to write integer conversion rules for. * Remove ArrayBase.newInitialisedArray, use default definition of newArray instead. * Bugs fixed: - {quot,rem}Word# primop attributes. - integerToInt64# for small negative values. - {min,max}Bound::Int on 64-bit platforms. - iShiftRL64#. - Various Bits instances. * Polishing: - Use 'ppr' instead of 'pprPrimOp' and 'text . showPrimRep'. - PrimRep.{primRepString,showPrimRepToUser} removed. - MachMisc.sizeOf returns Int instead of Integer. - Some eta reduction, parens, spacing, and reordering cleanups - sorry, couldn't resist. * Questions: - Should iShiftRL and iShiftRL64 be removed? IMHO they should, s/iShiftRA/iShiftR/, s/shiftRL/shiftR/. The behaviour on shifting is a property of the signedness of the type, not the operation! I haven't done this change.
* [project @ 2001-02-22 16:48:24 by qrczak]qrczak2001-02-221-3/+2
| | | | Since fromInt was degraded to a function, do the same with toInt.
* [project @ 2001-02-22 13:17:57 by simonpj]simonpj2001-02-221-3/+2
| | | | | | | | | | | | | | fromInt Remove fromInt from class Num, though it is retained as an overloaded operation (with unchanged type) in PrelNum. There are quite a few consequential changes in the Prelude. I hope I got them all correct! Also fix a bug that meant Integer (and its instances) wasn't getting slurped in by the renamer, even though it was needed for defaulting.
* [project @ 2000-06-30 13:39:35 by simonmar]simonmar2000-06-301-1/+4
| | | | | | - fix copyrights - remove some unused imports - comment formatting fixes
* [project @ 2000-04-06 00:04:01 by andy]andy2000-04-061-1/+1
| | | | Changing PrimPrel to PrelPrim
* [project @ 2000-04-04 02:20:30 by andy]andy2000-04-041-2/+1
| | | | Using the new Prelude structure to handle prims.
* [project @ 2000-03-14 12:16:00 by simonmar]simonmar2000-03-141-5/+5
| | | | | | | | | | | | | | | Simplfy the mutable array story: - rename MutableArray to STArray (and similarly for all operations on MutableArray, eg newArray is now newSTArray). - remove the extra level of indirection between STArrays and MutableArrays. - remove the MutableArray interface from hslibs/lang/MutableArray. This module will go away soon - Andy, don't bother porting it to Hugs.
* [project @ 2000-03-09 21:16:49 by andy]andy2000-03-091-1/+0
| | | | Wibble: rm needless import Prelude used by Hugs.
* [project @ 2000-03-09 13:33:01 by panne]panne2000-03-091-4/+4
| | | | Changed an #ifdef so that the Prelude can be builit again by GHC.
* [project @ 2000-03-09 06:14:38 by andy]andy2000-03-091-3/+14
| | | | | | | | | | | | | | | improving the synatax and semantics of the privileged import Typical use might be: import Prelude import privileged Prelude ( IORef , unsafePerformIO ) Which means please ignore the export that comes with Prelude, and let me at compiler internal magic operations, IORef and unsafePerformIO (both are later exported by IOExt) I've also updated the stdlib files to use this (hugs only :-).
* [project @ 2000-01-23 09:55:17 by andy]andy2000-01-231-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GHC now uses the "Hugs" split function, which is believed to have better behaviour: it is not unsafe, is deterministic, and works better with QuickCheck, a major client. Rational for the Record, quoted from Mark Jones mail on the Hugs list: [Mark Jones] A couple of months ago, John Hughes sent me mail about a problem that he had uncovered with the implementation of the Random library in Hugs. He had been using the "split" function in an attempt to generate a stream of random number generators, each of which he hoped would be different from the others. But instead he found that he actually ended with many different copies of the *same* random number generator. A disappointing, and frustratingly non-random result. If you don't happen to recall, split is a member of the RandomGen class, with type RandomGen g => g -> (g,g); it takes a single random number generator as its argument, and returns a pair of two new generators as its result. The only thing that the specification requires is that the two generators returned are (a) distinct and (b) `independently robust' from a statistical point of view. To the best of my knowledge, the implementation in Hugs meets this modest specification. Sadly, assuming only this specification, you cannot write the function that John was looking for and be sure that it will generate more than two different generators. For example, the specification allows even the following trivial implementation for split: split _ = (g1, g2), where g1 and g2 are some arbitrary but constant pair of distinct, and independently robust generators. With this implementation, you can split as often as you want and you'll never get more that two generators. Hugs and GHC (as far as I can tell) both use definitions of the form: split g = (g, f g) for some function f. (My understanding of the code in GHC is that it uses an unsafe function for f, breaking referential transparency; I hope the optimizer knows about this.) Note that this definition returns the argument as a result; the specification doesn't prohibit that; all it requires is that the two results returned be distinct. But if you try to generate a list of n different generators using: take n (iterate (fst . split) g) then you will be sorely disappointed; you might as well have written replicate n g. (On the other hand, if you were lucky enough to have used (snd . split), instead of (fst . split), then you wouldn't have noticed the problem ...) I know very little about the mathematics or pragmatics of random number generators, so I'm not sure that I know how to fix this problem. However, starting from this position of ignorance, I have hacked up a new version of "split" for the standard "StdGen" that will appear in the next release of Hugs (real soon now!). Judging from the tests that I've tried so far, it seems to work much better than the old version. That said: - Take care if you use Random.split in your programs, because it may not do what you expect. - There should probably be an errata about this for the Haskell 98 library report ... if somebody can figure out what it should say. - If you use Hugs, be aware that the implementation of Random.split was hacked up by someone who has no way of justifying that implementation, beyond some simple experiments. - If you know something about the mechanics of random number generators, here's an area where Haskell specifications and implementations could benefit from your knowledge! All the best, Mark [end quote]
* [project @ 1999-12-20 10:34:27 by simonpj]simonpj1999-12-201-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements a substantial re-organisation of the Prelude It also fixes a couple of small renamer bugs that were reported recently (notably, Sven pointed out that we weren't reporting unused imports properly) My original goal was to get rid of all "orphan" modules (i.e. ones with instance decls that don't belong either to a tycon or a class defined in the same module). This should reduce the number of interface files that have to be read when compiling small Haskell modules. But like most expeditions into the Prelude Swamp, it spiraled out of control. The result is quite satisfactory, though. GONE AWAY: PrelCCall, PrelNumExtra NEW: PrelReal, PrelFloat, PrelByteArr, PrelNum.hi-boot (The extra PrelNum.hi-boot is because of a tiresome thin-air Id, addr2Integer, which used to be in PrelBase.) Quite a lot of types have moved from one module to another, which entails some changes to part of the compiler (PrelInfo, PrelMods) etc, and there are a few places in the RTS includes and even in the driver that know about these home modules (alas). So the rough structure is as follows, in (linearised) dependency order [this list now appears in PrelBase.lhs] PrelGHC Has no implementation. It defines built-in things, and by importing it you bring them into scope. The source file is PrelGHC.hi-boot, which is just copied to make PrelGHC.hi Classes: CCallable, CReturnable PrelBase Classes: Eq, Ord, Functor, Monad Types: list, (), Int, Bool, Ordering, Char, String PrelTup Types: tuples, plus instances for PrelBase classes PrelShow Class: Show, plus instances for PrelBase/PrelTup types PrelEnum Class: Enum, plus instances for PrelBase/PrelTup types PrelMaybe Type: Maybe, plus instances for PrelBase classes PrelNum Class: Num, plus instances for Int Type: Integer, plus instances for all classes so far (Eq, Ord, Num, Show) Integer is needed here because it is mentioned in the signature of 'fromInteger' in class Num PrelReal Classes: Real, Integral, Fractional, RealFrac plus instances for Int, Integer Types: Ratio, Rational plus intances for classes so far Rational is needed here because it is mentioned in the signature of 'toRational' in class Real Ix Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples PrelArr Types: Array, MutableArray, MutableVar Does *not* contain any ByteArray stuff (see PrelByteArr) Arrays are used by a function in PrelFloat PrelFloat Classes: Floating, RealFloat Types: Float, Double, plus instances of all classes so far This module contains everything to do with floating point. It is a big module (900 lines) With a bit of luck, many modules can be compiled without ever reading PrelFloat.hi PrelByteArr Types: ByteArray, MutableByteArray We want this one to be after PrelFloat, because it defines arrays of unboxed floats. Other Prelude modules are much easier with fewer complex dependencies.
* [project @ 1999-11-22 12:12:09 by sewardj]sewardj1999-11-221-5/+9
| | | | Implement Random.setStdGen and Random.getStdGen for Hugs.
* [project @ 1999-10-29 01:16:48 by andy]andy1999-10-291-3/+53
| | | | | | | Adding in the modified versions of the Standard Haskell 98 libraries. These should compile under both Hugs and GHC. use the flags -D__HUGS__ -DUSE_REPORT_PRELUDE to extract the Hugs src.
* [project @ 1999-08-30 18:19:39 by simonpj]simonpj1999-08-301-0/+1
| | | | Adjust library imports to get fromInt/toInt from PrelNum
* [project @ 1999-07-06 16:45:31 by simonpj]simonpj1999-07-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All Simon's recent tuning changes. Rough summary follows: * Fix Kevin Atkinson's cant-find-instance bug. Turns out that Rename.slurpSourceRefs needs to repeatedly call getImportedInstDecls, and then go back to slurping source-refs. Comments with Rename.slurpSourceRefs. * Add a case to Simplify.mkDupableAlt for the quite-common case where there's a very simple alternative, in which case there's no point in creating a join-point binding. * Fix CoreUtils.exprOkForSpeculation so that it returns True of (==# a# b#). This lack meant that case ==# a# b# of { True -> x; False -> x } was not simplifying * Make float-out dump bindings at the top of a function argument, as at the top of a let(rec) rhs. See notes with FloatOut.floatRhs * Make the ArgOf case of mkDupableAlt generate a OneShot lambda. This gave a noticeable boost to spectral/boyer2 * Reduce the number of coerces, using worker/wrapper stuff. The main idea is in WwLib.mkWWcoerce. The gloss is that we must do the w/w split even for small non-recursive things. See notes with WorkWrap.tryWw. * This further complicated getWorkerId, so I finally bit the bullet and make the workerInfo field of the IdInfo work properly, including under substitutions. Death to getWorkerId. Kevin Glynn will be happy. * Make all lambdas over realWorldStatePrimTy into one-shot lambdas. This is a GROSS HACK. * Also make the occurrence analyser aware of one-shot lambdas. * Make various Prelude things into INLINE, so that foldr doesn't get inlined in their body, so that the caller gets the benefit of fusion. Notably in PrelArr.lhs.
* [project @ 1999-05-18 14:59:04 by simonpj]simonpj1999-05-181-0/+1
| | | | ../compiler/msg_prel
* [project @ 1999-05-13 11:00:07 by sof]sof1999-05-131-1/+1
| | | | | | randomIvalInteger: The difference between '1' and 'l' is rather slight at the level of pixels. At the level of Haskell programs however, the difference is rather more pronounced :)
* [project @ 1999-05-11 09:15:19 by sof]sof1999-05-111-33/+31
| | | | couple of fixes (courtesy of MPJ)
* [project @ 1999-05-05 10:39:25 by sof]sof1999-05-051-11/+12
| | | | Improved the splitting of the std. generator
* [project @ 1999-03-31 09:47:40 by sof]sof1999-03-311-1/+1
| | | | The bugfix that time forgot
* [project @ 1999-01-14 18:12:47 by sof]sof1999-01-141-34/+220
| | | | | | | Changes to make the Prelude comply with Haskell 98. I claim that this completes GHC's implementation of Haskell 98 (at least feature-wise, but there's bound to be some bugs lurking..)
* [project @ 1998-12-02 13:17:09 by simonm]simonm1998-12-021-1/+1
| | | | Move 4.01 onto the main trunk.
* [project @ 1998-02-02 17:27:26 by simonm]simonm1998-02-021-0/+67
Library re-organisation: All libraries now live under ghc/lib, which has the following structure: ghc/lib/std -- all prelude files (libHS.a) ghc/lib/std/cbits ghc/lib/exts -- standard Hugs/GHC extensions (libHSexts.a) -- available with '-fglasgow-exts' ghc/lib/posix -- POSIX library (libHSposix.a) ghc/lib/posix/cbits -- available with '-syslib posix' ghc/lib/misc -- used to be hslibs/ghc (libHSmisc.a) ghc/lib/misc/cbits -- available with '-syslib misc' ghc/lib/concurrent -- Concurrent libraries (libHSconc.a) -- available with '-concurrent' Also, several non-standard prelude modules had their names changed to begin with 'Prel' to reduce namespace pollution. Addr ==> PrelAddr (Addr interface available in 'exts') ArrBase ==> PrelArr CCall ==> PrelCCall (CCall interface available in 'exts') ConcBase ==> PrelConc GHCerr ==> PrelErr Foreign ==> PrelForeign (Foreign interface available in 'exts') GHC ==> PrelGHC IOHandle ==> PrelHandle IOBase ==> PrelIOBase GHCmain ==> PrelMain STBase ==> PrelST Unsafe ==> PrelUnsafe UnsafeST ==> PrelUnsafeST