Mutable Arrays

2000-05-09 Thread Marc van Dongen

Hello again,


Sorry for asking again but I can't find the
answer in the on line user manual.

What does one have to do to use mutable arrays?
An old program won't compile anymore with a very
recent ghc from CVS. I am using GlaExts.

Thanks in advance.

Regards,

Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: Mutable Arrays

2000-05-09 Thread Michael Weber

On Tue, May 09, 2000 at 11:37:46 +0100, Marc van Dongen wrote:
 What does one have to do to use mutable arrays?
 An old program won't compile anymore with a very
 recent ghc from CVS. I am using GlaExts.

$ cvs log ghc/lib/std/PrelArr.lhs

revision 1.19
date: 2000/03/14 12:16:00;  author: simonmar;  state: Exp;  lines: +57 -57
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.


Cheers,
Michael
-- 
Lehrstuhl-Kinderkrippe   Michael Weber [EMAIL PROTECTED]
Lehrstuhl für Informatik II
RWTH Aachen
WWW: http://www-i2.informatik.rwth-aachen.de/Software/Haskell/




Re: Mutable Arrays

2000-05-09 Thread Marc van Dongen

Michael Weber ([EMAIL PROTECTED]) wrote:

[...]

: $ cvs log ghc/lib/std/PrelArr.lhs
: 
: revision 1.19
: date: 2000/03/14 12:16:00;  author: simonmar;  state: Exp;  lines: +57 -57
: 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.

Thanks! Compiles hapilly now.

Regards,


Marc




RE: strangeness with `Exception.tryAll'

2000-05-09 Thread Simon Marlow

  tryAll (runST (return (error "BANG!")))
  
  will return (Right (error "BANG!")), because return isn't strict.
 
 Nope, 
   main = tryAll (runST (return (error "BANG!"::( = print
 yields `Left "BANG!"'!
 
 
 but
   main = tryAll (runST (
return ((error "BANG!", 42) :: (Int,Int))
)) = print
 
 leads to an error (for the reason you mentioned).

Yes, you're right.  I was confusing this with

tryAllIO (return (error "BANG!"))

which will return 'Right (error "BANG!")'.

 Maybe someone can add a note about this gotcha in the docs
 (sec-exception.html#3.8.3)?

Ok, I'll add a note about it.

Cheers,
Simon




RE: Showing tuples

2000-05-09 Thread Chris Angus

Do you derive Show for MyData?

 -Original Message-
 From: Mike Jones [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2000 05:58
 To: [EMAIL PROTECTED]
 Subject: Showing tuples
 
 
 Hi,
 
 I am having trouble with Show and tuples.
 
 I have a data structure, say:
 
 data MyData = ...
 
 And a value, say:
 
 value = (MyData..., MyData..., MyData)
 
 Then try to:
 
 show value
 
 I get a compiler message from ghc 4.05 that says:
 
 No instance for `Show (MyData, MyData, MyData)...
 
 What is the best way to deal with this problem?
 
 Thanks,
 
 Mike
 
 




Re: When is it safe to cheat?

2000-05-09 Thread Jan Skibinski



On Tue, 2 May 2000, Keith Wansbrough wrote:

 Off-topic, I know, but even if this worked as I think you intend, 
 it would hardly be random and would certainly be unsuitable for use as a
 nonce.  Applying `mkStdGen' to the current time doesn't make it any more
 random!  You might as well use
 
 nonce size = take size (cycle (map chr (chop_into_smaller_bits timeFrom1970)))
 
 where chop_into_smaller_bits expresses timeFrom1970 in base 36 or something.
 
 An attacker can certainly guess within a few seconds (= a few trials) when your 
connection was negotiated.
 

Good point. Short of reading some truly random device
(perhaps ambient temperature fluctuation) this can be always
theoretically defeated. I can only make life more difficult
to the attacker by trying to outsmart him algoritmically
(Or to confuse him. My clock is always several hours too late
 or too early. Just kidding)
 
Any good idea? First prize: a bottle of something good. :-)

Jan
 








Re: When is it safe to cheat?

2000-05-09 Thread Frank Atanassow

Jan Skibinski writes:
   Good point. Short of reading some truly random device
   (perhaps ambient temperature fluctuation) this can be always
   theoretically defeated. I can only make life more difficult
   to the attacker by trying to outsmart him algoritmically
   (Or to confuse him. My clock is always several hours too late
or too early. Just kidding)

   Any good idea? First prize: a bottle of something good. :-)

There is a thing known as an Entropy Gathering Demon (EGD). 

From http://www.lothar.com/tech/crypto/ :

One of the nice features of the Linux kernel is the /dev/random
device. This is a little character device that gives you random
numbers when you read it. In a variety of places scattered
throughout the kernel, certain interrupts (network packets arriving,
keyboard hits, mouse movement) cause a timestamp and some event
information to be hashed into an "entropy pool". The pool, perhaps
4k in size, always contains very random data, but as bits are
"stirred" in, a counter is incremented to reflect the fact that the
poll is now even more random than before. When you read from
/dev/random, you get a hashed portion of the pool, and the counter
is decremented. This gives you high quality cryptographically strong
random data.

...

EGD is an Entropy Gathering Daemon meant to be used on systems that
can run GPG* but which don't have this convenient source of random
bits. It is a regular user-space program that sits around, running
programs like 'w' and 'last' and 'vmstat', collecting the randomness
(or at least the unpredictability) inherent in the output of these
system statistics programs when used on a reasonably busy system. It
slowly stirs the output of these gathering programs into a pool of
entropy, much like the linux kernel device, and allows other programs
to read out random bits from this pool.

* GPG = GNU Privacy Guard

-- 
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791





Re: When is it safe to cheat?

2000-05-09 Thread Ketil Malde

Jan Skibinski [EMAIL PROTECTED] writes:

 Any good idea? First prize: a bottle of something good. :-)

The easiest ought to simply have enough granularity in the
gettimeofday() or equivalent.  Sure you can guess the approximate time 
in hours or seconds, but can you guess it in micro- or nanoseconds?

(Is there a clock cycle counter on modern CPUs?  That would give you
ns resolution, on modern hardware).  Modern motherboards also have
temperature and voltage sensors - although I don't know if the
granularity is good enough.

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants




Re: When is it safe to cheat?

2000-05-09 Thread Jan Skibinski



On Tue, 9 May 2000, Frank Atanassow wrote:

 Jan Skibinski writes:
  Any good idea? First prize: a bottle of something good. :-)
 
 There is a thing known as an Entropy Gathering Demon (EGD). 
 
 From http://www.lothar.com/tech/crypto/ :

You have been nominated for the first prize, 
thank you. That's all make sense to me. Now
that I know I should blame myself for not
noticing this little daemon running all the time
on our machines. But to give others a chance
I will postpone the final announcement :-)
Jan

P.S. 
I do not have a clue as yet why my mailer mishandled
my question about sources of randomness. I thought
it was sent few days ago. Sorry if you received it twice. 
I had few hardware problems recently, the servers
were down few times. Add to it yesterday's terrifying
storm - I could not belive my eyes when I saw sparks
coming out the receptacles. What a week!



 
 






RE: Showing tuples

2000-05-09 Thread Mike Jones

Chris,

Yes, I do derive Show for MyData. I was surprised it did not work.

Mike

-Original Message-
From: Chris Angus [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 09, 2000 12:57 AM
To: 'Mike Jones'; [EMAIL PROTECTED]
Subject: RE: Showing tuples


Do you derive Show for MyData?

 -Original Message-
 From: Mike Jones [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2000 05:58
 To: [EMAIL PROTECTED]
 Subject: Showing tuples
 
 
 Hi,
 
 I am having trouble with Show and tuples.
 
 I have a data structure, say:
 
 data MyData = ...
 
 And a value, say:
 
 value = (MyData..., MyData..., MyData)
 
 Then try to:
 
 show value
 
 I get a compiler message from ghc 4.05 that says:
 
 No instance for `Show (MyData, MyData, MyData)...
 
 What is the best way to deal with this problem?
 
 Thanks,
 
 Mike
 
 






Re: Showing tuples

2000-05-09 Thread Sven Panne

Mike Jones wrote:
 Yes, I do derive Show for MyData. I was surprised it did not work.

Deriving works, but GHC currently only contains instance declarations
for tuples up to 5 elements, so you have to write you own boring
instances for larger ones.  *yawn*

Cheers,
   Sven
-- 
Sven PanneTel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen  Oettingenstr. 67
mailto:[EMAIL PROTECTED]D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne




RE: Showing tuples

2000-05-09 Thread Chris Angus

Mike ... try this ...extend it to however long tuples you have


data MyData = Foo | Bar deriving Show

main = print (Foo,Foo,Foo,Foo,Foo,Foo)

instance (Show tv1, Show tv2, Show tv3, Show tv4, Show tv5 , Show tv6) =
Show (tv1,tv2,tv3,tv4,
tv5,tv6) where
showsPrec p (v1,v2,v3,v4,v5,v6) = showChar '(' . shows v1 . showChar
',' .
 shows v2 . showChar
',' .
 shows v3 . showChar
',' .
 shows v4 . showChar
',' .
 shows v5 . showChar
',' .
 shows v6 . showChar
')'

instance (Read tv1, Read tv2, Read tv3, Read tv4, Read tv5 , Read tv6) =
Read (tv1,tv2,tv3,tv4,
tv5,tv6) where
readsPrec p = readParen False
(\s0 - [((v1,v2,v3,v4,v5,v6),s6A) | ("(",s1) - lex
s0,
   (v1,s1A) - reads
s1,
   (",",s2) - lex
s1A,
   (v2,s2A) - reads
s2,
   (",",s3) - lex
s2A,
   (v3,s3A) - reads
s3,
   (",",s4) - lex
s3A,
   (v4,s4A) - reads
s4,
   (",",s5) - lex
s4A,
   (v5,s5A) - reads
s5,
   (",",s6) - lex
s5A,
   (v6,s6A) - reads
s6,
   (")",s3) - lex
s2A ])



 -Original Message-
 From: Mike Jones [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2000 14:54
 To: 'Chris Angus'
 Cc: [EMAIL PROTECTED]
 Subject: RE: Showing tuples
 
 
 Chris,
 
 Yes, I do derive Show for MyData. I was surprised it did not work.
 
 Mike
 
 -Original Message-
 From: Chris Angus [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, May 09, 2000 12:57 AM
 To: 'Mike Jones'; [EMAIL PROTECTED]
 Subject: RE: Showing tuples
 
 
 Do you derive Show for MyData?
 
  -Original Message-
  From: Mike Jones [mailto:[EMAIL PROTECTED]]
  Sent: 09 May 2000 05:58
  To: [EMAIL PROTECTED]
  Subject: Showing tuples
  
  
  Hi,
  
  I am having trouble with Show and tuples.
  
  I have a data structure, say:
  
  data MyData = ...
  
  And a value, say:
  
  value = (MyData..., MyData..., MyData)
  
  Then try to:
  
  show value
  
  I get a compiler message from ghc 4.05 that says:
  
  No instance for `Show (MyData, MyData, MyData)...
  
  What is the best way to deal with this problem?
  
  Thanks,
  
  Mike
  
  
 
 
 




Showing tuples

2000-05-09 Thread grust




Hi,

I am having trouble with Show and tuples.

I have a data structure, say:

data MyData = ...

And a value, say:

value = (MyData..., MyData..., MyData)

Then try to:

show value

I get a compiler message from ghc 4.05 that says:

No instance for `Show (MyData, MyData, MyData)...

What is the best way to deal with this problem?

Thanks,

Mike







RE: Showing tuples

2000-05-09 Thread grust




Do you derive Show for MyData?

 -Original Message-
 From: Mike Jones [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2000 05:58
 To: [EMAIL PROTECTED]
 Subject: Showing tuples


 Hi,

 I am having trouble with Show and tuples.

 I have a data structure, say:

 data MyData = ...

 And a value, say:

 value = (MyData..., MyData..., MyData)

 Then try to:

 show value

 I get a compiler message from ghc 4.05 that says:

 No instance for `Show (MyData, MyData, MyData)...

 What is the best way to deal with this problem?

 Thanks,

 Mike








RE: Showing tuples

2000-05-09 Thread Mike Jones



Sven,

That explains it. My tuples are of size 20.

Thanks,

Mike


Deriving works, but GHC currently only contains instance declarations
for tuples up to 5 elements, so you have to write you own boring
instances for larger ones.  *yawn*

Cheers,
   Sven
-- 
Sven PanneTel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen  Oettingenstr. 67
mailto:[EMAIL PROTECTED]D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne





Re: Converting float to double.

2000-05-09 Thread Marcin 'Qrczak' Kowalczyk

Mon, 8 May 2000 20:42:10 -0700 (PDT), Ronald J. Legere [EMAIL PROTECTED] pisze:

  I have a very simple question. What is the best way to 
 convert a float to a double?
  I use fromRational.toRational, and the notes in the prelude
 seem to imply that this is optimized into something sensible..

The Prelude contains:

realToFrac:: (Real a, Fractional b) = a - b
realToFrac = fromRational . toRational

Unfortunately GHC currently does not optimize this into anything
smarter than going through Rational. Fortunately it contains enough
machinery so you can let it optimize it yourself :-)  Just add:

import NumExts (floatToDouble, doubleToFloat)

{-# RULES
"realToFrac/Float-Double" realToFrac = floatToDouble
"realToFrac/Double-Float" realToFrac = doubleToFloat #-}

and compile with  -syslib lang -O  and use realToFrac.

To GHC developers: please add it to the GHC's library.

-- 
 __("Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/  GCS/M d- s+:-- a23 C+++$ UL++$ P+++ L++$ E-
  ^^  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK  5? X- R tv-- b+++ DI D- G+ e h! r--%++ y-





Re: When is it safe to cheat?

2000-05-09 Thread Michael Hobbs

Jan Skibinski wrote:
 Any good idea? First prize: a bottle of something good. :-)

In C, I've sometimes added in the memory location of an arbitrary
variable, just for good measure. But that's not quite as secure in an
open source environment. (Maybe not even that secure in a closed source
environment.) Probably not as good as the entropy daemon, anyway.

I believe that the P3 chips come with a noisy diode built-in,
specifically for the purpose of generating random numbers. You might try
to find a way to access that little gizmo. (Assuming that you're running
on a P3.)

- Michael Hobbs




Re: When is it safe to cheat?

2000-05-09 Thread Sverker Nilsson

Michael Hobbs wrote:
 I believe that the P3 chips come with a noisy diode built-in,
 specifically for the purpose of generating random numbers. You might try
 to find a way to access that little gizmo. (Assuming that you're running
 on a P3.)

Interesting! Do you have any reference for this? 

I hope this diode is only accessible from supervisor mode, because
otherwise we won't have as many provably deterministic user mode
programs as before.

Relevance for Haskell would be that you wouldnt be able to fork a
program written in C into a protected environment (functional
sandbox?) and know that its result would depend only on its input
arguments. So you couldnt safely do this thru an ordinary Haskell
function call that could be cached for example.

To get at this diode, or any other such device, one should have
to go thru a device driver or I/O instruction that could be disabled.
I hope they did it like this...

Sverker Nilsson


 
 - Michael Hobbs