Re: [Haskell-cafe] ST Monad - what's wrong?

2007-12-09 Thread pepe
The typechecker in 6.6.1 gets confused by the ($) and loses track of  
the 'freeness' of s (the thread variable) . The same code should work  
fine in 6.8.1, or alternatively in 6.6.1 without the ($).


Cheers
pepe


On 09/12/2007, at 12:11, Nicu Ionita wrote:


Hi,

I'm trying to use the ST monad in order to turn an almost pure  
function into
a pure one: reading a precalculated list of primes into a prime set.  
But the

following code brings an error:


primes :: Set Integer
primes = runST $ getPrimes primes10h7.txt



getPrimes :: String - (forall s. ST s (Set Integer))
getPrimes file =
   do cont - unsafeIOToST (readFile file)
  let set = fromList $ map read $ lines cont
  return set


And here is the error:

Couldn't match expected type `forall s. ST s a'
against inferred type `ST s (Set Integer)'
In the second argument of `($)', namely
`getPrimes primes10h7.txt'
In the expression: runST $ (getPrimes primes10h7.txt)
In the definition of `primes':
primes = runST $ (getPrimes primes10h7.txt)

Compiled with GHC 6.6.1 with extensions activated.

Nicu

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ST Monad - what's wrong?

2007-12-09 Thread Alfonso Acosta
On Dec 9, 2007 2:39 PM, pepe [EMAIL PROTECTED] wrote:
 The typechecker in 6.6.1 gets confused by the ($) and loses track of
 the 'freeness' of s (the thread variable) . The same code should work
 fine in 6.8.1, or alternatively in 6.6.1 without the ($).

True. However, note that the release notes of 6.8.1 encourage not to
rely in this new feature because it can change in the feature.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ST Monad - what's wrong?

2007-12-09 Thread Alfonso Acosta
 True. However, note that the release notes of 6.8.1 encourage not to
 rely in this new feature because it can change in the feature.


I obviously meant in the future, sorry.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ST Monad - what's wrong?

2007-12-09 Thread Stefan O'Rear
On Sun, Dec 09, 2007 at 12:11:42PM +0100, Nicu Ionita wrote:
 Hi,
 
 I'm trying to use the ST monad in order to turn an almost pure function into
 a pure one: reading a precalculated list of primes into a prime set. But the
 following code brings an error:
 
  primes :: Set Integer
  primes = runST $ getPrimes primes10h7.txt
 
  getPrimes :: String - (forall s. ST s (Set Integer))
  getPrimes file =
  do cont - unsafeIOToST (readFile file)
 let set = fromList $ map read $ lines cont
 return set
 
 And here is the error:
 
 Couldn't match expected type `forall s. ST s a'
 against inferred type `ST s (Set Integer)'
 In the second argument of `($)', namely
 `getPrimes primes10h7.txt'
 In the expression: runST $ (getPrimes primes10h7.txt)
 In the definition of `primes':
 primes = runST $ (getPrimes primes10h7.txt)

ST is far too big a hammer to use here.  It gives you safety you're not
using, at the cost of much more complicated typechecking.  I'd just use
unsafePerformIO.

Stefan


signature.asc
Description: Digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe