Re: Typesafe MRef with a regular monad

2003-06-24 Thread Ken Shan
Keith Wansbrough [EMAIL PROTECTED] wrote in article [EMAIL PROTECTED] in gmane.comp.lang.haskell.general: module TypedFM where data FM k -- Abstract; finite map indexed bykeys of type k data Key k a -- Abstract; a key of type k, indexing a value of type a empty

RE: Typesafe MRef with a regular monad

2003-06-16 Thread Simon Peyton-Jones
| If you use Simon PJ's type signatures, you can't really disallow using | a key from one map with another map. Yes, that's a good point. So there are really three issues: a) single-threaded-ness b) making sure you look up in the right map c) making sure the thing you

Re: Typesafe MRef with a regular monad

2003-06-16 Thread Ralf Hinze
Yes, that's a good point. So there are really three issues: a) single-threaded-ness b) making sure you look up in the right map c) making sure the thing you find has the right type Even if you have typed keys, (Key a), then if you look them up in the wrong map, any

Re: Typesafe MRef with a regular monad

2003-06-13 Thread Ashley Yakeley
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Carl R. Witty) wrote: Here's a hand-waving argument that you need either Typeable (or something else that has a run-time concrete representation of types) or ST/STRef (or something else, probably monadic, that can track unique objects) to do

Re: Typesafe MRef with a regular monad

2003-06-13 Thread Keith Wansbrough
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Carl R. Witty) wrote: Here's a hand-waving argument that you need either Typeable (or something else that has a run-time concrete representation of types) or ST/STRef (or something else, probably monadic, that can track unique objects)

Re: Typesafe MRef with a regular monad

2003-06-13 Thread Carl R. Witty
Keith Wansbrough [EMAIL PROTECTED] writes: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Carl R. Witty) wrote: Here's a hand-waving argument that you need either Typeable (or something else that has a run-time concrete representation of types) or ST/STRef (or something else,

Re: Typesafe MRef with a regular monad

2003-06-12 Thread Carl R. Witty
Simon Peyton-Jones [EMAIL PROTECTED] writes: | Conjecture: It's impossible to implement RefMonad directly in Haskell | without making use of built-in ST or IO functionality and without unsafe or | potentially diverging code (such as unsafeCoerce). A more concrete way to formulate a problem

Re: Typesafe MRef with a regular monad

2003-06-11 Thread Koen Claessen
Derek Elkins wrote: | The question (at least to me) is more, 'you can | satisfy the RefMonad interface with STRefs or IORefs, | but those use imperative features under the hood; | can it be satisfied without them?' As I showed in the message that spawned off this discussion, this is indeed

Re: Typesafe MRef with a regular monad

2003-06-11 Thread Koen Claessen
Someone asked me: | I don't recall the message you are referring to, and I | can't find it in the archive. Can you point me at it? Sorry, I meant: http://www.haskell.org/pipermail/haskell/2001-September/007922.html /K :-) ___ Haskell mailing list

Re: Typesafe MRef with a regular monad

2003-06-11 Thread Derek Elkins
On Wed, 11 Jun 2003 09:19:46 +0200 (MET DST) Koen Claessen [EMAIL PROTECTED] wrote: Derek Elkins wrote: | The question (at least to me) is more, 'you can | satisfy the RefMonad interface with STRefs or IORefs, | but those use imperative features under the hood; | can it be satisfied

Re: Typesafe MRef with a regular monad

2003-06-10 Thread oleg
update :: (Typable b) = FM k - Key k a - b - (FM ...) I didn't know constraints on values are allowed... Given below is the implementation of the required interface, in Haskell98 module TypedFM where data FM k -- Abstract; finite map indexed bykeys of type k data Key k

Re: Typesafe MRef with a regular monad

2003-06-10 Thread Derek Elkins
On Tue, 10 Jun 2003 11:44:45 -0700 (PDT) [EMAIL PROTECTED] wrote: update :: (Typable b) = FM k - Key k a - b - (FM ...) I didn't know constraints on values are allowed... Given below is the implementation of the required interface, in Haskell98 They aren't presumably as that would (as

Re: Typesafe MRef with a regular monad

2003-06-09 Thread Keith Wansbrough
Ralf Hinze writes: Why is that? Ok, here is my second implementation. It uses the Dynamic module from our HW2002 paper. A key is a pair consisting of the actual key and a type representation. [..] update:: (Typable b) = FM k - Key k a - b - (FM k, Key k b)

RE: Typesafe MRef with a regular monad

2003-06-09 Thread Simon Marlow
Simon P.J. writes: ... So it's reasonable that there should be some language extension. I'm just looking for the minimal such extension. unsafeCoerce# is quite a minimal extension :-) Cheers, Simon ___ Haskell mailing list [EMAIL

Re: Typesafe MRef with a regular monad

2003-06-06 Thread Ralf Hinze
A more concrete way to formulate a problem that I believe to be equivalent is this. Implement the following interface module TypedFM where data FM k -- Abstract; finite map indexed by keys of type k data Key k a-- Abstract; a key of type k, indexing

RE: Typesafe MRef with a regular monad

2003-06-06 Thread Simon Peyton-Jones
insert return a key. S | -Original Message- | From: Ralf Hinze [mailto:[EMAIL PROTECTED] | Sent: 06 June 2003 14:12 | To: Simon Peyton-Jones; Tim Sweeney; [EMAIL PROTECTED]; Ashley Yakeley | Subject: Re: Typesafe MRef with a regular monad | | A more concrete way to formulate a problem

Re: Typesafe MRef with a regular monad

2003-06-06 Thread Ralf Hinze
Am Freitag, 6. Juni 2003 15:23 schrieb Simon Peyton-Jones: Oh bother, I forgot to add that you can of course insert a new value with an old key (suitably typed) and have it overwrite. Else, as you say, there would not be much point. Maybe it'd be better to have a separate key-construction

RE: Typesafe MRef with a regular monad

2003-06-06 Thread Simon Peyton-Jones
such extension. Finite maps see a bit of a big hammer. Simon | -Original Message- | From: Ralf Hinze [mailto:[EMAIL PROTECTED] | Sent: 06 June 2003 14:29 | To: Simon Peyton-Jones; Tim Sweeney; [EMAIL PROTECTED]; Ashley Yakeley | Subject: Re: Typesafe MRef with a regular monad | | Am

Re: Typesafe MRef with a regular monad

2003-06-06 Thread Ralf Hinze
Am Freitag, 6. Juni 2003 15:47 schrieb Simon Peyton-Jones: Yes, one *could* use dynamic types. But the check would always succeed! Why is that? If I overwrite an entry with a value of a different type, then the check fails. I am certainly missing something ... Cheers, Ralf

RE: Typesafe MRef with a regular monad

2003-06-06 Thread Simon Peyton-Jones
; Tim Sweeney; [EMAIL PROTECTED]; Ashley Yakeley | Subject: Re: Typesafe MRef with a regular monad | | Am Freitag, 6. Juni 2003 15:47 schrieb Simon Peyton-Jones: | Yes, one *could* use dynamic types. But the check would always succeed! | | Why is that? If I overwrite an entry with a value

Re: Typesafe MRef with a regular monad

2003-06-06 Thread Ralf Hinze
Am Freitag, 6. Juni 2003 16:09 schrieb Simon Peyton-Jones: You can't overwrite an entry with a value of a different type, because the keys are typed! Any more than you can overwrite an IORef with a value of a different type. S Why is that? Ok, here is my second implementation. It uses the

RE: Typesafe MRef with a regular monad

2003-06-06 Thread George Russell
In fact I think these Typesafe MRef's are exactly equivalent to dynamic types. In other words, if you've got one, you've got the other. Ralf Hinze has just shown that if you have dynamic types you can implement Typesafe MRef. The reverse implementation would be something like data Dynamic = FM

Re: Typesafe MRef with a regular monad

2003-06-05 Thread Tim Sweeney
- From: Ashley Yakeley [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 04, 2003 5:19 PM Subject: Re: Typesafe MRef with a regular monad In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Ashley Yakeley wrote: ] ] Is it possible to actually implement a working instance

Re: Typesafe MRef with a regular monad

2003-06-05 Thread Derek Elkins
On Wed, 04 Jun 2003 15:19:53 -0700 Ashley Yakeley [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Ashley Yakeley wrote: ] ] Is it possible to actually implement a working instance of RefMonad in ] ] Haskell, without making use of a built-in monad like

Re: Typesafe MRef with a regular monad

2003-06-05 Thread Ashley Yakeley
In article [EMAIL PROTECTED], Derek Elkins [EMAIL PROTECTED] wrote: M = (forall s.ST s) R = STRef s e.g. runST :: (forall s.ST s a) - a you can use the same trick for your own RefMonad. I'm not sure if this will work with RefMonad exactly. If ST/STRef can be made an instance of