Changes in scoped type variable behavior?
Austin Seipp
mad.one at gmail.com
Fri Jan 23 17:47:05 EST 2009
Hi,
I've been reading Oleg Kiselyov's "Implicit Configurations" paper and
while getting the modulus math code to work I've hit a bit of a
problem.
The code is attached to this message; the problem is in the normalize
function:
> normalize :: (Modular s a, Integral a) => a -> M s a
> normalize a = M (mod a (modulus (u :: s)))
Trying this code gives:
> $ ghci implicit-config.hs
> GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
> [1 of 1] Compiling Main ( implicit-config.hs, interpreted
> )
>
> implicit-config.hs:34:24:
> Could not deduce (Modular s a)
> from the context (Modular s1 a, Integral a)
> arising from a use of `modulus' at implicit-config.hs:34:24-38
> Possible fix:
> add (Modular s a) to the context of
> the type signature for `normalize'
> In the second argument of `mod', namely `(modulus (u :: s))'
> In the first argument of `M', namely `(mod a (modulus (u :: s)))'
> In the expression: M (mod a (modulus (u :: s)))
> Failed, modules loaded: none.
> Prelude>
The paper uses the following code, which annotates the return of
normalize while at the same time binding the 's' type variable for use
on the right hand side:
> normalize :: (Modular s a, Integral a) ⇒ a → M s a
> normalize a :: M s a = M (mod a (modulus (u :: s)))
This code fails with:
> $ ghci implicit-config.hs
> GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
> [1 of 1] Compiling Main ( implicit-config.hs, interpreted
> )
>
> implicit-config.hs:34:0: Parse error in pattern
> Failed, modules loaded: none.
> Prelude>
Even with the ScopedTypeVariables extension - am I missing something?
I've also tried the actual literate haskell code from the technical
report and it fails with the same error (parse error in pattern.)
I'm using Mac OS X 10.6 and GHC 6.10.1.
Austin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: implicit-config.hs
Type: application/octet-stream
Size: 4091 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20090123/4bfa3f61/implicit-config.obj
More information about the Glasgow-haskell-users
mailing list