[Haskell-cafe] Problem with prepose.lhs and ghc6.10.1

oleg at okmij.org oleg at okmij.org
Fri Apr 3 02:22:34 EDT 2009


> ../haskell/prepose.lhs:707:0: Parse error in pattern
> which is pointing at:
> normalize a :: M s a = M (mod a (modulus (undefined :: s)))

The code indeed used lexically scoped type variables -- which GHC at
that time implemented differently. Incidentally, on the above line,
M s a is the type annotation on the result of (normalize a) rather
than on the argument 'a'. Therefore, putting a parentheses like
(a :: M s a) is wrong. Since the implementation of local type
variables in GHC changed over the years, it's best to get rid of them.
Here is the same line in the Hugs version of the code

> normalize :: (Modular s a, Integral a) => a -> M s a
> normalize a = r a __
>   where
>        r :: (Modular s a, Integral a) => a -> s -> M s a
>        r a s = M (mod a (modulus s))

Of course the signature for normalize can be omitted. Hugs did not
support lexically scoped type variables then (and probably doesn't
support now).

Today I would have written this definition simpler:

> normalize :: (Modular s a, Integral a) => a -> M s a
> normalize a = r
>   where r = M (mod a (modulus (tcar2 r)))
>
> tcar2:: f s x -> s
> tcar2 = undefined

(the function tcar2 is used in a few other places in the Hugs code,
for a similar purpose).



More information about the Haskell-Cafe mailing list