Re: Changes in scoped type variable behavior?

2009-01-23 Thread David Menendez
2009/1/23 Austin Seipp :
>
> 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)))

"s" isn't scoped over the definition of "normalize" in this
definition. You need an explicit "forall".

normalize :: forall s a. (Modular s a, Integral a) => a -> M s a
normalize a = M (mod a (modulus (u::s)))

See section 8.8.6 of the GHC manual.




-- 
Dave Menendez 

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Changes in scoped type variable behavior?

2009-01-23 Thread Austin Seipp
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


implicit-config.hs
Description: Binary data
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users