Type system compiler flags

Hello everyone, I am trying to compile some code that I have written a long time ago (might have been for ghc 6.3), and I have not done much Haskell in the meantime. I have trouble compiling the code, maybe only because I do not remember the necessary flags (yes, these should be in the source files), maybe because ghc has changed. I do for example have functions like this: getnArray :: Int -> [Word8] -> Maybe (UArray Int Word8, [Word8]) getnArrayST :: Int -> [Word8] -> (forall s . ST s (Maybe (UArray Int Word8, [Word8]))) getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) = do (a :: STUArray s Int Word8) <- newArray_ (0,n-1) let loop k bs | k == n = do fa <- freeze a return $ Just (fa, bs) | k < n = case bs of (b:bs) -> do writeArray a k b loop (k+1) bs [] -> return Nothing loop 0 bs getnArray n bs = runST (getnArrayST n bs) Can someone suggest compiler flags which will make this compile with 6.8 and 6.12? I have tried -XRankNTypes -XScopedTypeVariables -fglasgow-exts but still get "Parse error in pattern" for the definition of getnArrayST. Thanks for helping. As soon as I have overcome this problem, the real fun will begin, because my program uses Template Haskell ;) Carsten

On Tuesday 01 February 2011 10:20:26, Carsten Schultz wrote:
Hello everyone,
I am trying to compile some code that I have written a long time ago (might have been for ghc 6.3), and I have not done much Haskell in the meantime. I have trouble compiling the code, maybe only because I do not remember the necessary flags (yes, these should be in the source files), maybe because ghc has changed.
GHC has changed pretty much. I don't know whether there's a way to make your code compile with flags, without changing the code itself.
I do for example have functions like this:
getnArray :: Int -> [Word8] -> Maybe (UArray Int Word8, [Word8]) getnArrayST :: Int -> [Word8] -> (forall s . ST s (Maybe (UArray Int Word8, [Word8])))
getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) =
Get rid of such signatures, this is where you get a parse error, I don't know if there's a way to make GHC parse it at all. I doubt it.
do (a :: STUArray s Int Word8) <- newArray_ (0,n-1)
Move the signature to the RHS, a <- newArray_ (0,n-1) :: ST s (STUArray s Int Word8)
let loop k bs
| k == n = do fa <- freeze a
return $ Just (fa, bs)
| k < n = case bs of
(b:bs) -> do writeArray a k b loop (k+1) bs [] -> return Nothing loop 0 bs
getnArray n bs = runST (getnArrayST n bs)
With those changes (and ScopedTypeVariables), it compiles.

Am 01.02.11 11:05, schrieb Daniel Fischer:
On Tuesday 01 February 2011 10:20:26, Carsten Schultz wrote:
Hello everyone,
I am trying to compile some code that I have written a long time ago (might have been for ghc 6.3), and I have not done much Haskell in the meantime. I have trouble compiling the code, maybe only because I do not remember the necessary flags (yes, these should be in the source files), maybe because ghc has changed.
GHC has changed pretty much. I don't know whether there's a way to make your code compile with flags, without changing the code itself.
I do for example have functions like this:
getnArray :: Int -> [Word8] -> Maybe (UArray Int Word8, [Word8]) getnArrayST :: Int -> [Word8] -> (forall s . ST s (Maybe (UArray Int Word8, [Word8])))
getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) =
Get rid of such signatures, this is where you get a parse error, I don't know if there's a way to make GHC parse it at all. I doubt it.
do (a :: STUArray s Int Word8) <- newArray_ (0,n-1)
Move the signature to the RHS,
a <- newArray_ (0,n-1) :: ST s (STUArray s Int Word8)
let loop k bs
| k == n = do fa <- freeze a
return $ Just (fa, bs)
| k < n = case bs of
(b:bs) -> do writeArray a k b loop (k+1) bs [] -> return Nothing loop 0 bs
getnArray n bs = runST (getnArrayST n bs)
With those changes (and ScopedTypeVariables), it compiles.
It indeed does, even though I doubted it at first. As far as I remember the type in getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) = used to be necessary to bind the type variable s. Apparently things have become easier. Thank you, Carsten

It indeed does, even though I doubted it at first. As far as I remember the type in
getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) =
used to be necessary to bind the type variable s. Apparently things have become easier.
The higher-rank inference has been changed quite a bit, but I think -XPatternSignatures is all you were missing to get your original code to compiler (well, at least to parse). Jules

On Tuesday 01 February 2011 11:45:58, Julian Bean wrote:
It indeed does, even though I doubted it at first. As far as I remember the type in
getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) =
used to be necessary to bind the type variable s. Apparently things have become easier.
The higher-rank inference has been changed quite a bit, but I think -XPatternSignatures is all you were missing to get your original code to compiler (well, at least to parse).
No, I tried, the parser still choked on the above signature. You can get the other one, (a :: STUArray s Int Word8), to be parsed with PatternSignatures, but A pattern type signature cannot bind scoped type variables `s' unless the pattern has a rigid type context In the pattern: a :: STUArray s Int Word8 In a stmt of a 'do' expression: (a :: STUArray s Int Word8) <- newArray_ (0, n - 1) In the expression: do { (a :: STUArray s Int Word8) <- newArray_ (0, n - 1); let loop k bs | k == n = ... | k < n = ...; loop 0 bs } even if you remove the forall from getnArrayST's type signature. I don't know why `s' is a scoped type variable without the forall and ScopedTypeVariables, but that's what 6.12.3 says. 7.0.1 complains about No instance for (MArray (STUArray s) Word8 (ST s1)) which I understand.
Jules

Am 01.02.11 12:34, schrieb Daniel Fischer:
On Tuesday 01 February 2011 11:45:58, Julian Bean wrote:
It indeed does, even though I doubted it at first. As far as I remember the type in
getnArrayST n bs :: ST s (Maybe (UArray Int Word8, [Word8])) =
used to be necessary to bind the type variable s. Apparently things have become easier.
The higher-rank inference has been changed quite a bit, but I think -XPatternSignatures is all you were missing to get your original code to compiler (well, at least to parse).
No, I tried, the parser still choked on the above signature.
It seems that -XPatternSignatures is an old option replaced by -XScopedTypeVariables. By the way, it turned out that I had already adapted the library to a newer version of ghc some time ago and only not found the source file because I had also changed its name. In the new version I removed some probably misguided optimisation and replaced the above code by the following ;) getnArray :: Int -> [Word8] -> Maybe (UArray Int Word8, [Word8]) getnArray n bs | length (take n bs) == n = seq a (Just (a, bs'')) where (bs', bs'') = (take n bs, drop n bs) a = listArray (0,n-1) bs' getnArray _ _ = Nothing So I am sorry that my question was unnecessary, but I am still glad that I have learned that less work is now necessary to have the original code type-check. Thanks to both of you, Carsten
participants (3)
-
Carsten Schultz
-
Daniel Fischer
-
Julian Bean